Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
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.
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
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?
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
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
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
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]
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
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
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
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]
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
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)
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
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.
Posts: 74
Threads: 19
Joined: Aug 2012
Reputation:
0
i think i am too late to help you
|