zhshqzyc
asked on
Edit or Add database
Hello,
I want to insert two fields into or update database accordingly. It depends, if there are not such ones existing in the database, then insert them. If they are already there, it may be updated.
The two fields come from two text boxs.
I only finish insert part, can we put them together?
I want to insert two fields into or update database accordingly. It depends, if there are not such ones existing in the database, then insert them. If they are already there, it may be updated.
The two fields come from two text boxs.
I only finish insert part, can we put them together?
protected void Add_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MembershipDB"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Insert MedOrganization(OrgCode, OrgName) values(@OrgCode,@OrgName)";
cmd.Parameters.Add("OrgCode", SqlDbType.VarChar).Value = TextBox1.Text;
cmd.Parameters.Add("OrgName", SqlDbType.VarChar).Value = TextBox2.Text;
cmd.ExecuteNonQuery();
Response.Redirect("ManageUsers.aspx");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or maybe use OrgCode as identifier
ASKER
Can it prevent the duplication recodes because of mistakenly inserting?
@@rowcount shows the number of rows updated by the previous update statement, so if @@rowcount = 0 this means that no rows were updated and you can do Insert