Database Update

Mayfield2268

Active member
Joined
Feb 24, 2003
Messages
30
Hello

Im trying to run a update statment to a MS Access database. I get the following error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error:


Line 129:
Line 130:
Line 131: cmd.ExecuteNonQuery()
Line 132: dgNewAccount.ShowFooter = True
Line 133: dgNewAccount.EditItemIndex = -1


Does anyone have an idea as to why this error is occuring.

Thanks


This is the implemented code:

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\Database\NewClosedAccount.mdb"
Dim Conn As System.Data.OleDB.OleDbConnection = New System.Data.OleDb.OleDbConnection(strConn)
Conn.Open()

Dim MemberName As TextBox = e.Item.FindControl("txtMemberName")
Dim AccountNumber As TextBox = e.Item.FindControl("txtAccountNumber")
Dim Suffix1 As TextBox = e.Item.FindControl("txtSuffix1")
Dim Suffix2 As TextBox = e.Item.FindControl("txtSuffix2")
Dim ReferredBy As TextBox = e.Item.FindControl("txtReferredBy")
Dim OpenedBy As DropDownList = CType(e.Item.FindControl("ddlOpenedBy"), DropDownList)
Dim tDate As TextBox = e.Item.FindControl("txtDate")
Dim ID As Label = e.Item.FindControl("lblID")

Dim sql As String
sql = "UPDATE NewAccount SET MemberName = @MemberName, AccountNumber = @AccountNumber, "
sql = sql & "Suffix1 = @Suffix1, Suffix2 = @Suffix2, ReferredBy = @ReferredBy, OpenedBy = @OpenedBy, "
sql = sql & "DateOpened = @Date WHERE ID = @ID"



Dim cmd As New System.Data.OleDb.OleDbCommand()
cmd.CommandText = sql
cmd.Connection = conn
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@MemberName", MemberName.Text))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@AccountNumber", CInt(AccountNumber.Text)))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Suffix1", Suffix1.Text))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Suffix2", Suffix2.Text))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@RefferedBy", ReferredBy.Text))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@OpenedBy", OpenedBy.SelectedItem.Value))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Date", tDate.Text))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ID", ID.Text))


cmd.ExecuteNonQuery()
Conn.Close()
 
I think you need to add something like this after you add all your parameters:

cmd.Parameters("@membername").Value = membername.text
etc
etc
 
Back
Top