Yazma ve okumayı tarif eden bir örnek hazırladım. Aşağıdaki kod yardımcı olacaktır;
void Main()
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
TextBox textbox = new TextBox();
textbox.Multiline = true;
textbox.Dock = DockStyle.Fill;
Button button = new Button();
button.Text = "Gönder";
button.Dock = DockStyle.Bottom;
button.Click += (sender, args) =>
{
using (SqlConnection openCon = new SqlConnection("Data Source=localhost;Initial Catalog=Cargo;Integrated Security=True"))
{
string sqlKomut = "INSERT into [StokItem] ([Airwaybill]) VALUES (@VERİ)";
using (SqlCommand command = new SqlCommand(sqlKomut))
{
var veri = textbox.Text;
command.Connection = openCon;
command.Parameters.AddWithValue("@VERİ", veri);
openCon.Open();
command.ExecuteNonQuery();
textbox.Text = "";
}
}
};
Button button2 = new Button();
button2.Text = "Oku";
button2.Dock = DockStyle.Bottom;
button2.Click += (sender, args) =>
{
using (SqlConnection openCon = new SqlConnection("Data Source=localhost;Initial Catalog=Cargo;Integrated Security=True"))
{
openCon.Open();
string sqlKomut = "SELECT Airwaybill FROM StokItem";
using (SqlCommand command = new SqlCommand(sqlKomut, openCon))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
var sqlveri = reader.GetString(0);
textbox.Text = sqlveri;
}
}
}
}
};
form.Controls.Add(textbox);
form.Controls.Add(button);
form.Controls.Add(button2);
form.Show();
}
Software Engineer
https://www.volsoft.com.trhttps://www.doccastle.com