Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用c中的where从文本框插入数据以访问数据库#_C#_C# 4.0 - Fatal编程技术网

C# 如何使用c中的where从文本框插入数据以访问数据库#

C# 如何使用c中的where从文本框插入数据以访问数据库#,c#,c#-4.0,C#,C# 4.0,嗨,伙计们,我有Access数据库,上面有一些数据,ID是自动号码ex ID 17,还有一列在名称“电话号码ex:222”下,所以我现在想在同一列电话号码中输入另一个电话号码,因为此人有两个电话号码 OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into data ( [Phone number] ) values ('" + textBox

嗨,伙计们,我有Access数据库,上面有一些数据,ID是自动号码ex ID 17,还有一列在名称“电话号码ex:222”下,所以我现在想在同一列电话号码中输入另一个电话号码,因为此人有两个电话号码

OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into data ( [Phone number] ) values ('" + textBox3.Text + "') WHERE [ID] like  '" + textBox15.Text + "'  ";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
System.Windows.Forms.MessageBox.Show("Data Inserted Successfully");
con.Close();

Insert用于添加新行。如果要向现有行添加/更改数据,请使用
update
。。同样,使用
但没有任何
%
就像使用
=
插入一个新记录,不需要任何WHERE,如果要更新现有记录,则使用带有WHERE条件的更新。这种方法从根本上说是有缺陷的。您需要在该表上使用外键将电话号码链接到其所有者谢谢各位,我将使用update,但我希望添加此新电话号码,而不是删除它或将其更改为其他号码,或者如果我在搜索中使用外键,它将带来所有号码Insert用于添加新行。如果要向现有行添加/更改数据,请使用
update
。。同样,使用
但没有任何
%
就像使用
=
插入一个新记录,不需要任何WHERE,如果要更新现有记录,则使用带有WHERE条件的更新。这种方法从根本上说是有缺陷的。您需要在此表中使用外键将电话号码链接到其所有者谢谢各位,我将使用更新,但我希望添加此新电话号码,而不是删除它或将其更改为其他号码,或者如果我在搜索中使用外键,它是否会带来所有号码
 OleDbCommand cmd = new OleDbCommand();
 cmd.CommandType = CommandType.Text;
 cmd.CommandText = "insert into [data] ( [Date],[Name] ) values ('" + textBox1.Text + "','" + textBox2.Text + "')";
 cmd.Connection = con;
 con.Open();
 cmd.ExecuteNonQuery();
 System.Windows.Forms.MessageBox.Show("Data Inserted Successfully");
 con.Close();