Problem on insert data into Datagridview
-
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 StringTry 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.
-
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 StringTry 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.
-
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 StringTry 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.
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
, isNothing
, ornull
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