<% @ Import namespace = "system.data"%> <% @ import namespace = "system.data.oledb"%>
protected void Page_Load (Object Src, EventArgs E) {string strConnection = "Provider = Microsoft.Jet.OleDb.4.0;"; strConnection = @ "Data Source = // genfs1 / www11 / etning / xml / Northwind.mdb"; IF (! ispostback) bindgrid ();
Public void addemoyees_click (object sender, eventargs e) {if (Employeid.Value == "|| LastName.Value ==" "|| firstname.value ==" "|| homephone.value ==") {Message .Innerhtml = "EER:" EmployeeID "," Lastname "OR" homephone "no hhhhhhong"; message.style ["color"] = "red"; bindgrid (); return;}
String insertstr = "insert into Employees (EmployeeID, LastName, FirstName, HomePhone, Address, City, Country, Notes, PostalCode) values (@EmployeeID, @LastName, @FirstName, @HomePhone, @Address, @City, @Country, @ Notes, @PostalCode) "; OleDbCommand strCommand = new OleDbCommand (insertstr, strConnection); int cmdresults = 0; OleDbCommand2.CommandText =" NewAuthor. "; OleDbCommand2.CommandType = CommandType.StoredProcedure; OleDbCommand2.Parameters [" EmployeeID "] Value = TextBox1.Text; OleDbCommand2.Parameters [ "LastName"] Value = TextBox2.Text;. OleDbCommand2.Parameters [ "FirstName"] Value = TextBox3.Text;.. OleDbCommand2.Parameters [ "HomePhone"] Value = TextBox4.Text; OleDbCommand2 .Parameters [ "Address"] Value = TextBox5.Text;. OleDbCommand2.Parameters [ "City"] Value = TextBox6.Text;. OleDbCommand2.Parameters [ "Country"] Value = TextBox7.Text;. OleDbCommand2.Parameters [ "Notes "] .Value = textbox8.text; OLEDBCOM . Mand2.Parameters [ "PostalCode"] Value = CheckBox1.Checked; OleDbConnection2.Open (); try {cmdresults = OleDbCommand2.ExecuteNonQuery ();} catch (Exception ex) {MessageBox.Show ( "Failed to execute command, err = " EX.MESSAGE);} oledbconnection2.close (); MessageBox.show (" Number of Records Inserted = " CMDRESULTS.TOSTRING ());
Mycommand.connection.close ();
Bindgrid ();
public void BindGrid () {string strSQL = "SELECT * FROM Employees"; DataSet objDataSet = new DataSet (); OleDbConnection objConnection = new OleDbConnection (strConnection); OleDbDataAdapter objAdapter = new OleDbDataAdapter (strSQL, objConnection); objAdapter.Fill (objDataSet, "Employees"); DataView ObjDataView = New DataView (ObjdataSet.Tables ["Employees"]); MyDataGrid.DataSource = ObjDataView; myDataGrid.Database ();} script>