Insert Data In Database
-
Hi i want to know how to Insert Data Into Database table from textbox on button click..? Here's my codes..
namespace DataBindingListBox { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public SqlConnection connection; public SqlCommand command; string sql = "Select Number From Tnumber"; string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"; public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { BindData(); } private void BindData() { DataSet dtSet = new DataSet(); using (connection = new SqlConnection(connectionString)) { command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(); connection.Open(); adapter.SelectCommand = command; adapter.Fill(dtSet, "Tnumber"); listBox1.DataContext = dtSet; } } private void BindXmlData() { //listBox1.DataContext = BooksData ; } private void button1_Click(object sender, RoutedEventArgs e) { } } }
-
Hi i want to know how to Insert Data Into Database table from textbox on button click..? Here's my codes..
namespace DataBindingListBox { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public SqlConnection connection; public SqlCommand command; string sql = "Select Number From Tnumber"; string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"; public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { BindData(); } private void BindData() { DataSet dtSet = new DataSet(); using (connection = new SqlConnection(connectionString)) { command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(); connection.Open(); adapter.SelectCommand = command; adapter.Fill(dtSet, "Tnumber"); listBox1.DataContext = dtSet; } } private void BindXmlData() { //listBox1.DataContext = BooksData ; } private void button1_Click(object sender, RoutedEventArgs e) { } } }
Just read some basic tutorials which ae easily available on google
himanshu
-
Just read some basic tutorials which ae easily available on google
himanshu
-
string sql = "Insert into "TableName" (Column Name) values('Column Value')"; string connectionString = @"Data Source='local\SQLEXPRESS';Integrated Security=True;Pooling=False;Initial Catalog='MASTER'"; DataSet dtSet = new DataSet(); using (connection = new SqlConnection(connectionString)) { command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(dtSet); }
himanshu
-
Just read some basic tutorials which ae easily available on google
himanshu
Is this himanshu kashyap from amritsar??
-
Is this himanshu kashyap from amritsar??
yes
himanshu