Skip to content
Loading
  • 0
    1.   GridView1.DataSource=  cmd.ExecuteNonQuery();      
    2.  GridView1.DataBind();    
    3.   
    4. }     
    Would you be datasource = tblUser 
     
    ?? 
    0
  • Sachin Singh
    0
    yes , with connection in the grid it was tbluser so in codebehind i used the same.
    0
  • 0
    This is how the error appears
     
     
    0
  • Sachin Singh
    0
    open your aspx page and delete sqldatasource in the header of Grid. the error will be resolved.
    0
  • Rijwan Ansari
    0
    First hide the Label12 in page load
     
    as shown:
    1. protected void Page_Load(object sender, EventArgs e)    
    2. {    
    3.     if(!IsPostBack())  
    4.     {  
    5.         Label2.Visible = false;  
    6.     }  
    7.     
    8. }    
    Then show  it in Button1_Click and Button3_Click as shown:
    1. protected void Button1_Click(object sender, EventArgs e)    
    2. {    
    3.     SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
    4.     SqlCommand cmd = new SqlCommand("insert into tblUser (EMPNAME,PASSWORD) values (@EMPNAME,@PASSWORD)", cn);  
    5.      cn.Open();    
    6.      cmd.Parameters.AddWithValue("EMPNAME", TextBox2.Text);    
    7.      cmd.Parameters.AddWithValue("PASSWORD", TextBox3.Text);    
    8.      cmd.ExecuteNonQuery();    
    9.      cn.Close();    
    10.      Label2.Visible = True;  
    11. }    
    12.   
    13. protected void Button3_Click(object sender, EventArgs e)    
    14. {    
    15.     SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
    16.     SqlCommand cmd = new SqlCommand("Update tblUser set PASSWORD=@PASSWORD where EMPNAME=@EMPNAME", cn);   
    17.     cn.Open();    
    18.     cmd.Parameters.AddWithValue("EMPNAME", TextBox2.Text);    
    19.     cmd.Parameters.AddWithValue("PASSWORD", TextBox3.Text);    
    20.     cmd.ExecuteNonQuery();    
    21.     cn.Close();    
    22.     Label2.Visible = True;  
    23. }    
    Then again hide it rest all the functions: Button2_Click and Button4_Click
     
    as shown 
     
    1. protected void Button2_Click(object sender, EventArgs e)    
    2. {    
    3.     SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
    4.     cn.Open();    
    5.     DataTable dt = new DataTable();    
    6.     SqlDataAdapter sd = new SqlDataAdapter("select EMPNAME,PASSWORD from tblUser where EMPNAME= '" +TextBox2.Text+"'", cn);    
    7.     sd.Fill(dt);    
    8.     if (dt.Rows.Count > 0)    
    9.     {    
    10.         TextBox2.Text=Convert.ToString(dt.Rows[0]["EMPNAME"]);    
    11.         TextBox3.Text=Convert.ToString(dt.Rows[0]["PASSWORD"]);    
    12.     }           
    13.     Label12.Visible = false;  
    14.     
    15. }    
    1. protected void Button4_Click(object sender, EventArgs e)    
    2. {    
    3.     SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
    4.     SqlCommand cmd = new SqlCommand("Delete from tblUser where EMPNAME=@EMPNAME", cn);    
    5.                
    6.     cn.Open();    
    7.     TextBox2.Text = "";    
    8.     TextBox3.Text = "";    
    9.     cmd.ExecuteNonQuery();    
    10.     Label12.Visible  = false;  
    11.     
    12. } 
    This will solve your problem.
     
    Regards
    Rijwan
    0