BP Forums
help with my error - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: help with my error (/showthread.php?tid=640)



help with my error - jochen29 - 09-08-2012

my erro:

Value cannot be null.
Parameter name: dataSet

heres my code:

[code2=vbnet]Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click



Dim da As New MySqlDataAdapter("Update personalinfo, schoolinfo set sno = '" & txtSno.Text & "',
lastname = '" & txtLastName.Text & "',
middlename = '" & txtMiddleName.Text & "',
gender = '" & cmbGender.Text & "',
dateofbirth = '" & txtBirthday.Text & "',
school = '" & txtCollege.Text & "',
course = '" & cmbCourse.Text & "',
department = '" & txtDepartment.Text & "',
dateenrolled = '" & txtEnrolled.Text & "',
yeargraduated = '" & txtGraduated.Text & "',
where no = '" & txtSno.Text & "'", MySQLConn)

da.Fill(ds)
Me.Hide()

frmMain.showData()[/code2]

im trying to edit and save the info here.. the error appears above.


Re: help with my error - brandonio21 - 09-08-2012

Is the error being produced on this line?
[code2=vbnet]da.Fill(ds)[/code2]

If so, where do you create ds? Where exactly is the error being thrown?


Re: help with my error - jochen29 - 09-08-2012

yes its on that line

the error is:

ArgumentNullException was unhandled,
Valu Cannot be null. Parameter name: dataSet


i initialize the ds at the top before the
public class frmEdit
like this

Code:
Public Class frmEdit


    Dim MySQLConn As MySqlConnection
    Dim da As MySqlDataAdapter
    Dim ds As DataSet



Re: help with my error - brandonio21 - 09-08-2012

Well, just as the error message says
Value Cannot be null. Parameter name: dataSet

When you create a variable of any sort of object, the variable is defaulted to a value of null. So, you need to assign a value to ds. Something like this, perhaps:
[code2=vbnet]Dim MySQLConn As MySqlConnection
Dim da As MySqlDataAdapter
Dim ds As DataSet = New DataSet("newDataSet")[/code2]


Re: help with my error - jochen29 - 09-08-2012

when i did that another error occured.

InvalidOperationException was unhandled
Fill:SelectCommand.Connection property has not been initialized.

the same place where the error occured in ds


Re: help with my error - brandonio21 - 09-08-2012

This is because somewhere in your code you must specify that
[code2=vbnet]da.Connection = MySQLConn[/code2]

However, this will also throw an error, so you must also change
this
[code2=vbnet]Dim MySQLConn As MySqlConnection[/code2]
to this:
[code2=vbnet]Dim MySQLConn As MySqlConnection = New MySqlConnection[/code2]


Re: help with my error - jochen29 - 09-09-2012

but i already have this.
in the save button?
Code:
Dim da As New MySqlDataAdapter("Update personalinfo, schoolinfo set sno = '" & txtSno.Text & "',
lastname = '" & txtLastName.Text & "',
middlename = '" & txtMiddleName.Text & "',
gender = '" & cmbGender.Text & "',
dateofbirth = '" & txtBirthday.Text & "',
school = '" & txtCollege.Text & "',
course = '" & cmbCourse.Text & "',
department = '" & txtDepartment.Text & "',
dateenrolled = '" & txtEnrolled.Text & "',
yeargraduated = '" & txtGraduated.Text & "',
where no = '" & txtSno.Text & "'", MySQLConn)



Re: help with my error - brandonio21 - 09-09-2012

Ah okay, I simply overlooked that! Sorry!

Hmm.

Well, with your current code, you are creating an adapter and you are sending in your Command Text and Connection variables via the parameters. However, I believe that this error is occurring because you do not actually have a MySqlCommand variable. Try revising your code so it contains a MySqlCommand variable (And be sure to link it to the connection), as such:

[code2=vbnet]Dim commandText As String = "Update personalinfo, schoolinfo set sno = '" & txtSno.Text & "', lastname = '" & txtLastName.Text & "', middlename = '" & txtMiddleName.Text & "', gender = '" & cmbGender.Text & "', dateofbirth = '" & txtBirthday.Text & "', school = '" & txtCollege.Text & "', course = '" & cmbCourse.Text & "', department = '" & txtDepartment.Text & "', dateenrolled = '" & txtEnrolled.Text & "', yeargraduated = '" & txtGraduated.Text & "', where no = '" & txtSno.Text & "'"

Dim MySQLConn As MySqlConnection = New MySqlConnection
Dim MySQLComm As MySqlCommand = New MySqlCommand(commandText, MySQLConn)
Dim da As MySqlDataAdapter
Dim ds As DataSet = New DataSet("newDataSet")

da = New MySqlDataAdapter(MySQLComm)[/code2]

This should resolve your problem. I have never actually tried connecting to a MySQL Server using the method that you are using, so I apologize if I am incorrect on the matter.


Re: help with my error - manishshrestha60 - 09-10-2012

i think i am too late to help you