using System.Data; using System.Data.OleDb; using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page { protected void Button1_Click(object sender, System.EventArgs e) { string DBpath = Server.MapPath("app_data/addressBook.mdb"); string ConnStr; string SQL;
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + DBpath + ";"; OleDbConnection MyOleDbConn = new OleDbConnection(ConnStr); MyOleDbConn.Open();
try { SQL = "select * from tblAddressBook"; OleDbCommand myOleDbCommand = new OleDbCommand(SQL, MyOleDbConn); object Result; Result = myOleDbCommand.ExecuteScalar(); Value.Text = "There are " + Result.ToString() + " products in the database";
OleDbDataAdapter myOleDbAdapter = new OleDbDataAdapter(); myOleDbAdapter.SelectCommand = new OleDbCommand(SQL, MyOleDbConn); DataSet myDS = new DataSet(); myOleDbAdapter.Fill(myDS);
GridView1.DataSource = myDS; GridView1.DataBind();
OleDbDataReader myOLEDataReader = myOleDbCommand.ExecuteReader();
Response.Write(""); while(myOLEDataReader.Read()) { Response.Write(myOLEDataReader.GetString(1) + " " + myOLEDataReader.GetString(2) + " " + myOLEDataReader.GetString(3) + " "); } Response.Write(""); } catch {
} finally { MyOleDbConn.Close(); } } protected void Button2_Click(object sender, System.EventArgs e) { string DBpath = Server.MapPath("app_data/addressBook.mdb"); string ConnStr;
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + DBpath + ";";
OleDbConnection myOleDbConnection = new OleDbConnection(ConnStr); string insertSQL; insertSQL = "INSERT into tblAddressBook (name,phone,email,address) VALUES ('" + txtName.Text + "','" + txtPhone.Text + "','" + txtEmail.Text + "','" + txtAddress.Text + "');"; OleDbCommand myOleDbCommand = new OleDbCommand(insertSQL, myOleDbConnection); myOleDbCommand.Connection.Open(); myOleDbCommand.ExecuteNonQuery(); myOleDbCommand.Connection.Close(); } }
|
| Author: sandeep 29 May 2008 | Member Level: Bronze Points : 2 |
can u tell me how to delete a row
|
| Author: sandeep 29 May 2008 | Member Level: Bronze Points : 2 |
can u tell me how to delete a row
|
| Author: Bindu Bujji 07 Jun 2008 | Member Level: Gold Points : 2 |
It is simple. Instead of insertSql define string called DeleteSql.
string DeleteSql; DeleteSq;= "DELTE FROM tblAddressBook WHERE NAME = '" + txtName.Text "' "
OleDbCommand myOleDbCommand = new OleDbCommand(DeleteSq;, myOleDbConnection); myOleDbCommand.Connection.Open(); myOleDbCommand.ExecuteNonQuery(); myOleDbCommand.Connection.Close();
Nice code snippet Komala
|