问题描述
con.Open();
//string un = TextBox1.Text;
SqlCommand cmd1 =新的SqlCommand("UPDATE userdet SET用户名= @ username,FirstName = @ FirstName,MiddleName = @ MiddleName,LastName = @LastName,组织= @ Organisation,Bussiness = @ Bussiness,Address1 = @ Address1,Address2 = @ Address2,城市= @城市,州= @州,国家= @国家,PinCode = @PinCode,电话= @Tel,电子邮件= @ Email,Doj = @Doj,传真= @fax,网站= @website,描述= @description, dat = @dat WHERE(用户名= @用户名)或(名字= @名)或(中间名= @中间名)或(姓氏= @姓氏)或(组织= @组织)或(业务= @业务)或(地址1 = @ Address1)或(地址2 = @ Address2)或(城市= @城市)或(州= @州)或(国家= @国家)或(PinCode = @PinCode)或(Tel = @Tel)或(电子邮件= @电子邮件)或(Doj = @Doj)或(传真= @fax)或(网站= @网站)或(描述= @描述)或(dat = @dat),con);
SqlCommand cmd2 =新的SqlCommand(更新用户表集username = @ username,password = @ password,ustatus = @ ustatus,其中username = @ username或password = @ password或ustatus = @ ustatus",等等);
//cmd1.Parameters.AddWithValue("@UserName,TextBox2.Text);
//cmd1.Parameters.AddWithValue("@ username1",TextBox1.Text);
//cmd2.Parameters.AddWithValue("@ username",TextBox1.Text);
cmd1.Parameters.AddWithValue("@ username",TextBox2.Text);
cmd1.Parameters.AddWithValue("@ FirstName",TextBox3.Text);
cmd1.Parameters.AddWithValue("@ MiddleName",TextBox4.Text);
cmd1.Parameters.AddWithValue("@ LastName",TextBox5.Text);
cmd1.Parameters.AddWithValue("@ Organisation",TextBox6.Text);
cmd1.Parameters.AddWithValue("@ Bussiness",TextBox7.Text);
cmd1.Parameters.AddWithValue("@ Address1",TextBox8.Text);
cmd1.Parameters.AddWithValue("@ Address2",TextBox9.Text);
cmd1.Parameters.AddWithValue("@ City",TextBox10.Text);
cmd1.Parameters.AddWithValue("@ State",TextBox11.Text);
cmd1.Parameters.AddWithValue("@ Country",TextBox12.Text);
cmd1.Parameters.AddWithValue("@ PinCode",TextBox13.Text);
cmd1.Parameters.AddWithValue("@ Tel",TextBox14.Text);
cmd1.Parameters.AddWithValue("@ Email",TextBox15.Text);
cmd1.Parameters.AddWithValue("@ Doj",TextBox16.Text);
cmd1.Parameters.AddWithValue("@ fax",TextBox17.Text);
cmd1.Parameters.AddWithValue("@ website",TextBox18.Text);
cmd1.Parameters.AddWithValue("@ description",TextBox19.Text);
cmd1.Parameters.AddWithValue("@ dat",TextBox20.Text);
cmd1.ExecuteNonQuery();
cmd2.Parameters.AddWithValue("@ username",TextBox2.Text);
cmd2.Parameters.AddWithValue("@ password",TextBox21.Text);
cmd2.Parameters.AddWithValue("@ ustatus",TextBox22.Text);
cmd2.ExecuteNonQuery();
Label21.Text =已更新";
con.Close();
在执行时.表中的所有行都将更改.实际上,如果我在userdet中将用户名设置为主键,则不会更新.为什么?我也想更新.请帮助
con.Open();
//string un = TextBox1.Text;
SqlCommand cmd1 = new SqlCommand("UPDATE userdet SET username = @username, FirstName = @FirstName, MiddleName = @MiddleName, LastName = @LastName, Organisation = @Organisation, Bussiness = @Bussiness, Address1 = @Address1, Address2 = @Address2, City = @City, State = @State, Country = @Country, PinCode = @PinCode, Tel = @Tel, Email = @Email, Doj = @Doj, fax = @fax, website = @website, description = @description, dat = @dat WHERE (username = @username) OR (FirstName = @FirstName) OR (MiddleName = @MiddleName) OR (LastName = @LastName) OR (Organisation = @Organisation) OR (Bussiness = @Bussiness) OR (Address1 = @Address1) OR (Address2 = @Address2) OR (City = @City) OR (State = @State) OR (Country = @Country) OR (PinCode = @PinCode) OR (Tel = @Tel) OR (Email = @Email) OR (Doj = @Doj) OR (fax = @fax) OR (website = @website) OR (description = @description) OR (dat = @dat)", con);
SqlCommand cmd2 = new SqlCommand("update usertable set username=@username,password=@password,ustatus=@ustatus where username=@username or password=@password or ustatus=@ustatus", con);
//cmd1.Parameters.AddWithValue("@UserName", TextBox2.Text);
// cmd1.Parameters.AddWithValue("@username1", TextBox1.Text);
// cmd2.Parameters.AddWithValue("@username", TextBox1.Text);
cmd1.Parameters.AddWithValue("@username", TextBox2.Text);
cmd1.Parameters.AddWithValue("@FirstName", TextBox3.Text);
cmd1.Parameters.AddWithValue("@MiddleName", TextBox4.Text);
cmd1.Parameters.AddWithValue("@LastName", TextBox5.Text);
cmd1.Parameters.AddWithValue("@Organisation", TextBox6.Text);
cmd1.Parameters.AddWithValue("@Bussiness", TextBox7.Text);
cmd1.Parameters.AddWithValue("@Address1", TextBox8.Text);
cmd1.Parameters.AddWithValue("@Address2", TextBox9.Text);
cmd1.Parameters.AddWithValue("@City", TextBox10.Text);
cmd1.Parameters.AddWithValue("@State", TextBox11.Text);
cmd1.Parameters.AddWithValue("@Country", TextBox12.Text);
cmd1.Parameters.AddWithValue("@PinCode", TextBox13.Text);
cmd1.Parameters.AddWithValue("@Tel", TextBox14.Text);
cmd1.Parameters.AddWithValue("@Email", TextBox15.Text);
cmd1.Parameters.AddWithValue("@Doj", TextBox16.Text);
cmd1.Parameters.AddWithValue("@fax", TextBox17.Text);
cmd1.Parameters.AddWithValue("@website", TextBox18.Text);
cmd1.Parameters.AddWithValue("@description", TextBox19.Text);
cmd1.Parameters.AddWithValue("@dat", TextBox20.Text);
cmd1.ExecuteNonQuery();
cmd2.Parameters.AddWithValue("@username", TextBox2.Text);
cmd2.Parameters.AddWithValue("@password", TextBox21.Text);
cmd2.Parameters.AddWithValue("@ustatus", TextBox22.Text);
cmd2.ExecuteNonQuery();
Label21.Text = "Updated";
con.Close();
while executing. all the rows in the table is getting changed. actually if i set username in userdet as primary key its not updating. why? i want to upadate that too. please help
推荐答案
这篇关于编辑选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!