Results 1 to 9 of 9

Thread: I can't load data on datagrid.

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    Philippines
    Posts
    32

    I can't load data on datagrid.

    I have created a program that loads a data through a datagrid. Can anyone help me?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I can't load data on datagrid.

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    Philippines
    Posts
    32

    Re: I can't load data on datagrid.

    ok.. here is my code..
    VB Code:
    1. Public Class WebForm1
    2.     Inherits System.Web.UI.Page
    3.  
    4. #Region " Web Form Designer Generated Code "
    5.  
    6.     'This call is required by the Web Form Designer.
    7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    8.         Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
    9.         Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
    10.         Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
    11.         Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
    12.         '
    13.         'OleDbDataAdapter1
    14.         '
    15.         Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
    16.         Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
    17.         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")})})
    18.         '
    19.         'OleDbSelectCommand1
    20.         '
    21.         Me.OleDbSelectCommand1.CommandText = "SELECT CostumerName, Product, UserID FROM Table1"
    22.         Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
    23.         '
    24.         'OleDbInsertCommand1
    25.         '
    26.         Me.OleDbInsertCommand1.CommandText = "INSERT INTO Table1(CostumerName, Product, UserID) VALUES (?, ?, ?)"
    27.         Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
    28.         Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("CostumerName", System.Data.OleDb.OleDbType.VarWChar, 50, "CostumerName"))
    29.         Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Product", System.Data.OleDb.OleDbType.VarWChar, 50, "Product"))
    30.         Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("UserID", System.Data.OleDb.OleDbType.VarWChar, 50, "UserID"))
    31.         '
    32.         'OleDbConnection1
    33.         '
    34.         Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
    35.         "ocking Mode=1;Data Source=""C:\Documents and Settings\Administrator\桌面\wa.mdb"";Je" & _
    36.         "t OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System databa" & _
    37.         "se=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Sh" & _
    38.         "are Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=" & _
    39.         "False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Rep" & _
    40.         "lica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
    41.  
    42.     End Sub
    43.     Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    44.     Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    45.     Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    46.     Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    47.     Protected WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
    48.     Protected WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
    49.     Protected WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
    50.     Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    51.  
    52.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
    53.     'Do not delete or move it.
    54.     Private designerPlaceholderDeclaration As System.Object
    55.  
    56.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    57.         'CODEGEN: This method call is required by the Web Form Designer
    58.         'Do not modify it using the code editor.
    59.         InitializeComponent()
    60.     End Sub
    61.  
    62. #End Region
    63.  
    64.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    65.         'Put user code to initialize the page here
    66.     End Sub
    67.  
    68.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    69.         Dim dt As New DataTable
    70.         Me.OleDbSelectCommand1.CommandText = "SELECT CostumerName, Product, UserID FROM Table1 WHERE UserID = " & TextBox1.Text & ";"
    71.         OleDbDataAdapter1.Fill(dt)
    72.         Me.DataGrid1.DataSource = dt.DefaultView
    73.         Me.DataGrid1.DataBind()
    74.     End Sub
    75. End Class
    can you please help me...

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: I can't load data on datagrid.

    can you please help me...
    Possibly.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    Philippines
    Posts
    32

    Re: I can't load data on datagrid.

    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...

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I can't load data on datagrid.

    Moved from VB.NET Forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: I can't load data on datagrid.

    It throws an exception because you didn't supply a connection to your dataadapter.

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    Philippines
    Posts
    32

    Re: I can't load data on datagrid.

    i already have a connection.. but the problem is the database already open by another user..

  9. #9
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: I can't load data on datagrid.

    so what is the error? could you post the message of the error?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width