Deepak Ratan

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;
}
 
 
 

Answers (15)