简体   繁体   English

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

[英]how to insert data from textbox to access database using where in c#

Hi guys I have Access database that have some data on it and the ID is Auto Number ex ID 17 , and a Column under name phone number ex: 222 , so I want to now enter another phone number to same column phone number cuz this person have two phone number大家好,我有 Access 数据库,上面有一些数据,ID 是 Auto Number ex ID 17 ,名称电话号码下的列例如: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();
 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM