Friday, 30 August 2013

How to store textbox value in database? I am using SQL express with wpf

How to store textbox value in database? I am using SQL express with wpf

i am trying to insert textbox value into database with sqlconnection but i
cant insert it. after successful execution of query table was still null.
working with sqlexpress 2008 in wpf.
my code. private void button1_Click(object sender, RoutedEventArgs e) {
SqlConnection con = new SqlConnection("Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB1.mdf;Integrated
Security=True;User Instance=True");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into Table1
values('"+textBox1.Text+"');",con);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}

No comments:

Post a Comment