编辑选项 [英] edit option

查看:80
本文介绍了编辑选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

您不应该更新主键.
我建议您在表中使用一个序列号作为您的主键-然后可以根据需要更改用户名.
You are not supposed to update a primary key.
I suggest you use a serial no in your table which acts as your primary key - you can then change the username as you wish.


我认为您的问题是您的太多了,或者SQL语句中的子句.如果其中任何一个为真,则将更新该行.因此,很有可能每一行都包含一些传递至少一个子句的信息.例如,如果传真号码为空,它将通过没有传真号码的每一行.
I think your problem is that you have way too many OR clauses in you SQL statement. If ANY ONE of them is true, then that row will be updated. So there is a very good chance that every row contains some info that passes at least one of the clauses. For example, if the fax number if blank, it will pass every row that has no fax number.


这篇关于编辑选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆