これが私のフォームの外観で、私のコードは次のようになります。
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 を見つけ、いずれかを選択すると、データベースからのデータがテキスト ボックスに入力されるので、データを削除および更新する方法を知る必要があります。