Hi all,
I created a connection at the page load event and then dragged a gridview on the page and when I ran it, it worked just fine. Now I want to take the values of textbox1,2, & 3 and a checkbox and insert into the gridview or access db. Can you tell me what I'm doing wrong with the following codes
Code:Partial Class Page1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim xconn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\HP_Owner\My Documents\Visual Studio 2005\MyFinalWebSite/db1.mdb") ' creates a connection, althought I don't understand why "data.oledb" is needed Dim xcmd As New Data.OleDb.OleDbCommand("Select * from Table1", xconn) Dim xda As New Data.OleDb.OleDbDataAdapter(xcmd) Dim ds As New Data.DataSet xconn.Open() xda.Fill(ds, "Table1") GridView1.DataSource = ds.Tables("Table1") GridView1.DataBind() End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim xconn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\HP_Owner\My Documents\Visual Studio 2005\MyFinalWebSite/db1.mdb") ' Tries to insert into Table1 my access table Dim xcmd As New Data.OleDb.OleDbCommand("INSERT INTO [Table1] Set [LName] = textbox1.text,[FName] = textbox2.text, [Student] = checkbox1.text, [Known] = textbox3.text", xconn) Dim xda As New Data.OleDb.OleDbDataAdapter(xcmd) Dim ds As New Data.DataSet xconn.Open() xda.Fill(ds, "Table1") GridView1.DataSource = ds.Tables("Table1") GridView1.DataBind() End Sub End Class




Reply With Quote