i have my access database document already inserted and i wa
i have my access database document already inserted, and i want to link the search, save , Delete buttons to it. so that i would be able to record to my database document and to delete from it and search from it . what codes do i need to write behind each of those buttons to make it work . and please be very detail.
note : i am using access database document (OLEDb) and if there is connection string tell me exactly where to find it .
Solution
accessing ms acces database by using its drivers. jdbc odbc bridge driver is used to connect the database.
OLEDB also has more advantages than ODBC.
to establish a connection
OleDbConnection con = new OleDbConnection(\"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=yourdatabase.accdb\");
or use below:
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings[\"DBConnectionString\"].ConnectionString.Trim();
try the below code to performing basic opeartion on access databse.
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings[\"DBConnectionString\"].ConnectionString.Trim();
SqlCommand sqlCommand = new SqlCommand();
{
sqlConnection.Open();
sqlCommand.CommandText = \"Insert into Student (Name, Address, Phone) _values(\" + \"\'\"+txtName.Text +\"\'\"+ \",\" + \"\'\"+txtAddress.Text + \"\'\"+\", _
\" + \"\'\"+txtPhone.Text +\"\'\"+ \")\";//insert data into table
sqlCommand.Connection = sqlConnection;
sqlCommand.ExecuteNonQuery();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(\"Select * from Student \", sqlConnection); //code for reading database
DataSet dataSet = new DataSet();
sqlDataAdapter.Fill(dataSet);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(\"Select * from Student \", sqlConnection);//updating the database
DataSet dataSet = new DataSet();
sqlDataAdapter.Fill(dataSet);
SqlCommandBuilder sqlCom = new SqlCommandBuilder(sqlDataAdapter);
DataRow dataRow =dataSet.Tables[0].NewRow();
dataRow[0] = “Daniel”;
dataRow[1] = \"michigan\";
dataSet.Tables[0].Rows.Add(dataRow);
dataAdapter.Update(dataSet);
}
catch (Exception ex)
{
Response.Write(ex);
}
finally
{
sqlConnection.Close();
}

