I have created a program that loads a data through a datagrid. Can anyone help me?
Printable View
I have created a program that loads a data through a datagrid. Can anyone help me?
What do you need help with if you already did it? Post your code and show us where your stuck or where there is a error. ;)
ok.. here is my code..
can you please help me...VB Code:
Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection ' 'OleDbDataAdapter1 ' Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1 Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1 Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Table1", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("CostumerName", "CostumerName"), New System.Data.Common.DataColumnMapping("Product", "Product"), New System.Data.Common.DataColumnMapping("UserID", "UserID")})}) ' 'OleDbSelectCommand1 ' Me.OleDbSelectCommand1.CommandText = "SELECT CostumerName, Product, UserID FROM Table1" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 ' 'OleDbInsertCommand1 ' Me.OleDbInsertCommand1.CommandText = "INSERT INTO Table1(CostumerName, Product, UserID) VALUES (?, ?, ?)" Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1 Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("CostumerName", System.Data.OleDb.OleDbType.VarWChar, 50, "CostumerName")) Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Product", System.Data.OleDb.OleDbType.VarWChar, 50, "Product")) Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("UserID", System.Data.OleDb.OleDbType.VarWChar, 50, "UserID")) ' 'OleDbConnection1 ' Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _ "ocking Mode=1;Data Source=""C:\Documents and Settings\Administrator\桌面\wa.mdb"";Je" & _ "t OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System databa" & _ "se=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Sh" & _ "are Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=" & _ "False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Rep" & _ "lica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1" End Sub Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Protected WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter Protected WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand Protected WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dt As New DataTable Me.OleDbSelectCommand1.CommandText = "SELECT CostumerName, Product, UserID FROM Table1 WHERE UserID = " & TextBox1.Text & ";" OleDbDataAdapter1.Fill(dt) Me.DataGrid1.DataSource = dt.DefaultView Me.DataGrid1.DataBind() End Sub End Class
Possibly. :)Quote:
can you please help me...
ahm.. please show me what should i put in fom page_load. just connecting datagrid to oledbdataAdapter... to make it clear.. i put dim dt as new datatable then i put OleDbDataAdapter1.Fill(dt) <---the error is this...
Moved from VB.NET Forum. ;)
It throws an exception because you didn't supply a connection to your dataadapter.
i already have a connection.. but the problem is the database already open by another user..
so what is the error? could you post the message of the error?