Click here to Skip to main content
16,017,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I have created a web form with textboses and a database. I am confused now.....

when i created a table, i created it with UserID column and set primary key but on the web form i didnt included it..so i dont know if i must include it..if yes? can u please show me how as i have already done the coding


You are allowed to tell me were i must improve as a begginer.


find my code below..

protected void btnUpdate_Click(object sender, EventArgs e)
    {
      try
      {
       SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
       conn.Open();
       SqlCommand comm = new SqlCommand("Udate tblreg");
       comm.ExecuteNonQuery();
       txtuser.Text = "";
       txtPass.Text = "";
       txtFulln.Text = "";
       txtSurname.Text = "";
       txtemail.Text = "";
       dropCountry.SelectedItem.ToString();
       dropProvince.SelectedItem.ToString();

        conn.Close();

       Label1.Visible = true;
       Label1.Text = "Record Successfully Updated!!";
        }
        catch
        {
            Response.Write("Error Occurred!!");
        }
        finally
        {
            Response.Write("Executed");
        }



       
        
    }
}
Posted
Comments
[no name] 15-May-13 7:54am    
Your update statement is invalid, see http://www.w3schools.com/sql/sql_update.asp for how to use UPDATE.
Member 10010198 15-May-13 8:01am    
Please show me where?

1 solution

UPDATE statements need data to actually put into the fields, and it is a very good idea to limit the fields to just those you want to change:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("UPDATE myTable SET myColumn1=@C1, myColumn2=@C2 WHERE Id=@ID", con))
        {
        com.Parameters.AddWithValue("@ID", id);
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
Member 10010198 15-May-13 8:17am    
owk even though theres no textbox for ID on the webfoarm?
OriginalGriff 15-May-13 9:25am    
It;s an example. You probably want to replace all the column names to match your database...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900