这就是我的表单的样子,我的代码如下所示:
using System.Data.SqlClient;
namespace ProjectCSharpSQLserver
{
public partial class Form1 : Form
{
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=I:\ProjectCSharpSQLserver\ProjectCSharpSQLserver\CsSQL.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cn.Open();
SqlDataAdapter sda = new SqlDataAdapter("insert into info (id, Name, phone, Address) Values ('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "')", cn);
sda.Fill(dt);
cn.Close();
}
}
}
我需要知道如何打开组合框,找到 Id,选择一个,然后文本框由数据库中的数据填充,这样我就可以删除和更新数据。