A
Allen
Hey all I'm new to .net trying to update a database with a new calculated
values. I keep getting this error.
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred
in system.data.dll
Additional information: System error.
Public Function Debit(ByVal iStudentID As Integer) As Boolean
Dim dsCurrent As New DataSet
Dim dBalance As Double
Dim dPotentialBalance As Double
Dim strWarning As String
Dim frmMain As New frmStateUMain
' get the account balance using the argument for the Student ID
Dim sqlda As New SqlDataAdapter
Dim oCmd As SqlClient.SqlCommand
Dim strConn As String
strConn = Have connection string that works
Create the Command Object
oCmd = New SqlClient.SqlCommand
' Assign Connection to Command Object
oCmd.Connection = New SqlConnection(strConn)
' Open the Connection
oCmd.Connection.Open()
' Assign the SQL to the Command Object
oCmd.CommandText = "[GetAccountBalance]"
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Parameters.Add("@ID", System.Data.SqlDbType.Int, 0)
oCmd.Parameters("@ID").Value = iStudentID
Dim bal As Double = CDbl(oCmd.ExecuteScalar())
dBalance = bal
MessageBox.Show("SQL statement succeeded", _
dBalance)
'dsCurrent.Clear()
' Close the Connection
oCmd.Connection.Close()
Catch oExcept As Exception
dBalance = 0
MessageBox.Show("Error executing SQL: " & _
oExcept.Message, "btnExecute_Click()")
End Try
' this method will add the book price amount
' to the student's account balance.
Dim total As Double
total = dBalance + frmMain.cellValue
oCmd.Connection.Open()
oCmd.CommandText = "UPDATE Students SET AccountBalance = total WHERE
StudentID = iStudentID"
oCmd.CommandType = CommandType.Text
oCmd.ExecuteNonQuery()
RecordPurchase(iStudentID)
' commit the changes
' return success
Debit = True
values. I keep getting this error.
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred
in system.data.dll
Additional information: System error.
Public Function Debit(ByVal iStudentID As Integer) As Boolean
Dim dsCurrent As New DataSet
Dim dBalance As Double
Dim dPotentialBalance As Double
Dim strWarning As String
Dim frmMain As New frmStateUMain
' get the account balance using the argument for the Student ID
Dim sqlda As New SqlDataAdapter
Dim oCmd As SqlClient.SqlCommand
Dim strConn As String
strConn = Have connection string that works
Create the Command Object
oCmd = New SqlClient.SqlCommand
' Assign Connection to Command Object
oCmd.Connection = New SqlConnection(strConn)
' Open the Connection
oCmd.Connection.Open()
' Assign the SQL to the Command Object
oCmd.CommandText = "[GetAccountBalance]"
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Parameters.Add("@ID", System.Data.SqlDbType.Int, 0)
oCmd.Parameters("@ID").Value = iStudentID
Dim bal As Double = CDbl(oCmd.ExecuteScalar())
dBalance = bal
MessageBox.Show("SQL statement succeeded", _
dBalance)
'dsCurrent.Clear()
' Close the Connection
oCmd.Connection.Close()
Catch oExcept As Exception
dBalance = 0
MessageBox.Show("Error executing SQL: " & _
oExcept.Message, "btnExecute_Click()")
End Try
' this method will add the book price amount
' to the student's account balance.
Dim total As Double
total = dBalance + frmMain.cellValue
oCmd.Connection.Open()
oCmd.CommandText = "UPDATE Students SET AccountBalance = total WHERE
StudentID = iStudentID"
oCmd.CommandType = CommandType.Text
oCmd.ExecuteNonQuery()
RecordPurchase(iStudentID)
' commit the changes
' return success
Debit = True