0% found this document useful (0 votes)
49 views3 pages

Home Page

This document contains code for the homepage and profile pages of a social media application. The homepage code handles user login by retrieving username and password from textboxes, validating the credentials against a database, and redirecting to the profile page on success. The profile page code retrieves the username from the session, displays tweets by querying a database table, and allows adding new tweets which are also saved to the database. It uses SQL connections and commands to perform database operations like insert, select, and validation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

Home Page

This document contains code for the homepage and profile pages of a social media application. The homepage code handles user login by retrieving username and password from textboxes, validating the credentials against a database, and redirecting to the profile page on success. The profile page code retrieves the username from the session, displays tweets by querying a database table, and allows adding new tweets which are also saved to the database. It uses SQL connections and commands to perform database operations like insert, select, and validation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Home Page

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class Index : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnlogin_Click(object sender, EventArgs e)
{
string User_name;
User_name = txtusername.Text;
Session["name"] = User_name;

SqlConnection con = new SqlConnection("Data


Source=----------\\SQLEXPRESS;Initial Catalog=Twitter;Integrated
Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select *from registration where
username='" + txtusername.Text + "' and password='" + txtpassword.Text + "' ",
con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//Session["user"] = tbUsername.Text;
Response.Redirect("User.aspx");

}
else
{
lblMessage.Visible = true;
lblMessage.Text = "Invalid password";
}
}
protected void imgbtnsignup_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("SignUpReg.aspx");
}
}
Profile
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class User : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
string name1;
name1 = Session["name"].ToString();
Label1.Text = name1;

display();
}
protected void btntweet_Click(object sender, EventArgs e)
{

saveTweet(hidTweet.Value);
display();

}
//SqlConnection con = new SqlConnection("Data
Source=----------\\SQLEXPRESS;Initial Catalog=Twitter;Integrated
Security=True");
// con.Open();
// string str = "insert into tweets values('" + TextBox1.Text + "')";
// SqlCommand cmd = new SqlCommand(str, con);
// cmd.ExecuteNonQuery();
// con.Close();

private void saveTweet(string tweet)


{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["TwitterConnectionString"
].ToString());
//SqlConnection con = new SqlConnection("Data
Source=----------\\SQLEXPRESS;Initial Catalog=Twitter;Integrated
Security=True");
SqlCommand cmd = new SqlCommand("insert into tweets([tweets])
values(@tweet);", con);
SqlParameter para1 = new SqlParameter("@tweet", SqlDbType.NVarChar);
para1.Value = tweet;
cmd.Parameters.Add(para1);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
con.Close();
}
}
private void display()
{
SqlConnection con1 = new
SqlConnection(ConfigurationManager.ConnectionStrings["TwitterConnectionString"
].ToString());
string str = "Select *from tweets";
SqlCommand cmd = new SqlCommand(str, con1);
con1.Open();
cmd.ExecuteNonQuery();
con1.Close();
}

You might also like