TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deepak Ratan
NA
175
48.7k
I have to Pass the ID value to next table when its login
Apr 29 2015 2:04 AM
Table Name "A"
ID
UserName
Password
1
xxx
iii
2
yyy
iii
Table Name "B"
ID
Post_Data
Created_By
Created_At
NULL
hi
NULL
NULL
NULL
GM
NULL
NULL
This is my two tables when i am login the ID have to pass to second table ...But I am getting NULL Value What to do? PLEASE HELP
This is My code:
SAMPLE.aspx.cs
protected void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from TBL_Login where UserName =@UserName and Password=@Password", con);
cmd.Parameters.AddWithValue("@UserName", txtlogin.Text);
cmd.Parameters.AddWithValue("@Password", txtpassword.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Session["UserName"] = Convert.ToString(txtlogin.Text);
if (dt.Rows.Count > 0)
{
Response.Redirect("AthenaTechnologySolutions.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
Example.aspx.cs
public partial class AthenaTechnologySolutions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblsession.Text = "Welome " + Convert.ToString(Session["UserName"]);
if (!IsPostBack)
{
Update_Status();
}
}
protected void btnlogout_Click(object sender, EventArgs e)
{
Response.Redirect("LoginForm.aspx");
}
protected void btnpost_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
string query = "INSERT INTO TBL_Post (Post_data) VALUES (@Post_data)";
try
{
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add("@Post_data", txtpost.Text);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
public DataTable Update_Status()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
//SqlDataAdapter Adp = new SqlDataAdapter("select * from TBL_Post", con);
SqlCommand cmd = new SqlCommand("Proc_Login", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter Adp = new SqlDataAdapter();
Adp.SelectCommand = cmd;
DataTable Dt = new DataTable();
Adp.Fill(Dt);
statusgrdview.DataSource = Dt;
statusgrdview.DataBind();
return Dt;
}
Reply
Answers (
15
)
Refresh Listview data based on Selection of a Dropdown
how to delete if Forign Key is there (asp.net,sql)