OleDbCommand cmd; string cmdString = "INSERT INTO Contacts (FirstName,LastName,Phone,Mobile,Address) values('" + textBoxFirstName.Text + "','" + textBoxLastName.Text + "','" + textBoxPhone.Text + "','" + textBoxMobile.Text + "','" + textBoxAddress.Text + "')"; OleDbConnection myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); cmd = new OleDbCommand(cmdString, myConnection); myConnection.Open(); cmd.ExecuteNonQuery(); OleDbCommand myCommand = new OleDbCommand(); myCommand.CommandText = "Select * from Contacts"; myCommand.CommandType = CommandType.Text; myCommand.Connection = myConnection; OleDbDataAdapter myAdapter = new OleDbDataAdapter(); myAdapter.SelectCommand = myCommand; myAdapter.Fill(myTable); dataGridView.DataSource = null; dataGridView.DataSource = myTable.DefaultView; myAdapter.Dispose(); myCommand.Dispose(); myConnection.Close();
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)