Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem on insert data into Datagridview

Problem on insert data into Datagridview

Scheduled Pinned Locked Moved Visual Basic
databasehelpcsharpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drexler_kk
    wrote on last edited by
    #1

    Dear all, I'm new to VB.NET,I have this error: System.Data: Value cannot be null. Parameter name: dataSet I want to display the data search result into the datagridview for the user. But I found the above error. The following is my code,the user click button1(which is the search button),then it will search from the database. The message box I'm here have pop out like usual. Anyone can tell me whats wrong with it?

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim x As String

        Try
            If Trim(TextBox2.Text) <> "" Then
                x = TextBox2.Text.ToUpper
    
                SQL = "SELECT \* FROM company\_detail WHERE Comp\_Name LIKE '" & x & "%'"
                ObjComm = New MySqlCommand(SQL, ObjMyConn)
                ObjMyConn.Open()
                ObjRead = ObjComm.ExecuteReader
                If ObjRead.Read Then
                    MessageBox.Show("I'm here")
                    ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
                    ObjAdapter.Fill(ds, "Client\_Comp")
                    dt = ds.Tables("Client\_Comp")
                    DataGridView1.DataSource = dt
    
                End If
    
            End If
            ObjMyConn.Close()
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly)
        End Try
    
    End Sub
    

    Thank you for reading.

    L D 2 Replies Last reply
    0
    • D drexler_kk

      Dear all, I'm new to VB.NET,I have this error: System.Data: Value cannot be null. Parameter name: dataSet I want to display the data search result into the datagridview for the user. But I found the above error. The following is my code,the user click button1(which is the search button),then it will search from the database. The message box I'm here have pop out like usual. Anyone can tell me whats wrong with it?

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim x As String

          Try
              If Trim(TextBox2.Text) <> "" Then
                  x = TextBox2.Text.ToUpper
      
                  SQL = "SELECT \* FROM company\_detail WHERE Comp\_Name LIKE '" & x & "%'"
                  ObjComm = New MySqlCommand(SQL, ObjMyConn)
                  ObjMyConn.Open()
                  ObjRead = ObjComm.ExecuteReader
                  If ObjRead.Read Then
                      MessageBox.Show("I'm here")
                      ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
                      ObjAdapter.Fill(ds, "Client\_Comp")
                      dt = ds.Tables("Client\_Comp")
                      DataGridView1.DataSource = dt
      
                  End If
      
              End If
              ObjMyConn.Close()
          Catch ex As Exception
              MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly)
          End Try
      
      End Sub
      

      Thank you for reading.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Have you tried to omit the filter of the select-statement? Changing this line:

      SQL = "SELECT * FROM company_detail WHERE Comp_Name LIKE '" & x & "%'"

      To this:

      SQL = "SELECT * FROM company_detail"

      Does this have rows?

      I are troll :)

      1 Reply Last reply
      0
      • D drexler_kk

        Dear all, I'm new to VB.NET,I have this error: System.Data: Value cannot be null. Parameter name: dataSet I want to display the data search result into the datagridview for the user. But I found the above error. The following is my code,the user click button1(which is the search button),then it will search from the database. The message box I'm here have pop out like usual. Anyone can tell me whats wrong with it?

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As String

            Try
                If Trim(TextBox2.Text) <> "" Then
                    x = TextBox2.Text.ToUpper
        
                    SQL = "SELECT \* FROM company\_detail WHERE Comp\_Name LIKE '" & x & "%'"
                    ObjComm = New MySqlCommand(SQL, ObjMyConn)
                    ObjMyConn.Open()
                    ObjRead = ObjComm.ExecuteReader
                    If ObjRead.Read Then
                        MessageBox.Show("I'm here")
                        ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
                        ObjAdapter.Fill(ds, "Client\_Comp")
                        dt = ds.Tables("Client\_Comp")
                        DataGridView1.DataSource = dt
        
                    End If
        
                End If
                ObjMyConn.Close()
            Catch ex As Exception
                MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly)
            End Try
        
        End Sub
        

        Thank you for reading.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You didn't specify which line the error occurs on, but I can take an educated guess:

        ObjAdapter.Fill(ds, "Client_Comp")

        Your DataSet object, ds, is Nothing, or null in C#. You have to create an instance of a DataSet object to pass to the DataAdapter.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups