private void Save_Click(object sender, EventArgs e) { //******* For database using SQL EXPRESS *********** string conString = @"Initial Catalog=database_name;" + @"Data Source=.\SQLEXPRESS;"+ @"AttachDbFilename=\database_name.mdf;"+ @"Integrated Security=True;"+ @"User Instance=True;";
//******* For Database with SQL Server 2005 installed seperatly********
/* string conString = @"Initial Catalog=bookdata;" + @"Data Source=computername\SQLEXPRESS;"+ @"Integrated Security=True;" */ SqlConnection connection = new SqlConnection(conString); connection.Open(); String MyString = "INSERT INTO bookentry (AuthorName, BookTitle, Price) VALUES('"+ textBox2.Text+"' ,'"+ textBox3.Text+"' ,'"+ textBox4.Text +"' );"; SqlCommand command = new SqlCommand(MyString,connection); command.ExecuteNonQuery(); connection.Close(); label1.Text = "Successfull"; }
The above code is for a button event on clicking the button the information for textboxes are stored in the database residing on other server if you are using SQL Express then use the connection String mentioned seperately
|
No responses found. Be the first to respond and make money from revenue sharing program.
|