I can not figure out why I am getting this error. I have gone over everything and cant find any discrepancies.
I have confirmed that eveything matches up with the Database/tabel
Error:
Parameterized Query '(@.WorkSheetID nvarchar(14),@.Origin nvarchar(5),@.DealerName nvarc' expects parameter @.Address, which was not supplied.
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.SqlClient.SqlException: Parameterized Query '(@.WorkSheetID nvarchar(14),@.Origin nvarchar(5),@.DealerName nvarc' expects parameter @.Address, which was not supplied.
Source Error:
Line 401: .Add(New SqlParameter("@.DOB", sDOB))Line 402: End WithLine 403: myCommand.ExecuteNonQuery()Line 404: myConnection.Close()Line 405: 'Lets Check to see if there is a Co Applicant
My Code:
Protected
Sub bSubmitNC_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles bSubmitNC.ClickDim myConnectionAs SqlConnectionDim myCommandAs SqlCommandDim connStringAsString ="Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|CustomerInfo.mdf;Integrated Security=True;User Instance=True"Dim CPhoneNum, CWorkNum, CCellNum, sWorkSheetNum, sSaleOriginAsStringDim sDealerShipName, sBkupSlsRep, sDateCreated, sFirstName, sMiddleName, slastname, sBuyAddress, sSSN, sDOBAsStringDim scity, sState, sZip, sEmailAddres, sBuyersCounty, sSalesTaxAsStringDim SlsManLoginNAsStringDim myPrincipalAs IPrincipal =Me.User'Customer InformationsWorkSheetNum = lblCustWksnum.Text
sSaleOrigin = lblSaleOrigin.Text
sDealerShipName = lblDealerShipName.Text
sDateCreated = lblDateCreated.Text
sBkupSlsRep = lblBkupSlsRep.Text
sFirstName = lblcFirstName.Text
sMiddleName = lblcMiddleName.Text
slastname = lblcLastName.Text
sBuyAddress = rBuyAddress
scity = rcity
sState = rState
sZip = rZip
sEmailAddres = lblEmailAddres.Text
sBuyersCounty = lblBuyersCounty.Text
sSalesTax = lblSalesTax.Text
sSSN = lblSSN.Text
sDOB = lblDOB.Text
'Lets get the Current Logged on UserSlsManLoginN = lblSlsRep.Text
myConnection =
New SqlConnectionmyConnection.ConnectionString = connString
myConnection.Open()
CPhoneNum = lblHnum.Text
CWorkNum = lblWnum.Text
CCellNum = lblCnum.Text
Const sqlAsString ="Insert into CustomerTable (WorkSheetID, Origin, DealerName, DateCreated, SalesRep, " _+
"BkupSalesRep, FirstName, MiddleName, LastName, Address, City, State, Zip, HomePhone, WorkPhone, " _+
"CellPhone, Email, County, SalesTax, SS, DOB) Values(@.WorkSheetID, @.Origin, @.DealerName, @.DateCreated, " _+
"@.SalesRep, @.BkupSalesRep, @.FirstName, @.MiddleName, @.LastName, @.Address, @.City, @.State, @.Zip, @.HomePhone, @.WorkPhone, @.CellPhone, @.Email, @.County, @.SalesTax, @.SS, @.DOB)"myCommand =
New SqlCommand(sql, myConnection)With myCommand.Parameters.Add(
New SqlParameter("@.WorkSheetID", sWorkSheetNum)).Add(
New SqlParameter("@.Origin", sSaleOrigin)).Add(
New SqlParameter("@.DealerName", sDealerShipName)).Add(
New SqlParameter("@.DateCreated", sDateCreated)).Add(
New SqlParameter("@.SalesRep", SlsManLoginN)).Add(
New SqlParameter("@.BkupSalesRep", sBkupSlsRep)).Add(
New SqlParameter("@.FirstName", sFirstName)).Add(
New SqlParameter("@.MiddleName", sMiddleName)).Add(
New SqlParameter("@.LastName", slastname)).Add(
New SqlParameter("@.Address", sBuyAddress)).Add(
New SqlParameter("@.City", scity)).Add(
New SqlParameter("@.State", sState)).Add(
New SqlParameter("@.Zip", sZip)).Add(
New SqlParameter("@.HomePhone", CPhoneNum)).Add(
New SqlParameter("@.WorkPhone", CWorkNum)).Add(
New SqlParameter("@.CellPhone", CCellNum)).Add(
New SqlParameter("@.Email", sEmailAddres)).Add(
New SqlParameter("@.County", sBuyersCounty)).Add(
New SqlParameter("@.SalesTax", sSalesTax)).Add(
New SqlParameter("@.SS", sSSN)).Add(
New SqlParameter("@.DOB", sDOB))EndWithmyCommand.ExecuteNonQuery()
myConnection.Close()
EndIfEndIfEndSub
Make sure you clear the sqlParameters before you ever add something to it.
After looking at that code i'm pretty confused on which way you are trying to do this. Are you using sql stored procedures or regular sql statements?
Can you please post your sql stored procedure if your using one. I can help you further but I need to know what one your going to plan on using.
|||
I am not using any stored procedures... Under Server Exploror/Data Connections I just have the CustomerInfo.mdf./Tables I dont have anything under Stored procedures
Whats got me stumped is I had this working and was successfully populating data into my database.
And for somereason unknown to me, Its not working now
I did tested the Data Connecttion by right clicking on the CustomerInfo.mdf and choose the "test Connection" and it came back successful.
I dont have any other code. This is a simple Webform with Textboxes and labels. User just files in all the informationa and clicks the Submit button.
Any help would beso greatly appricated.
T
|||
I did some research online and ended up makingn some changes... I am not getting any errors now but no data is being populated??
Here is what I changed to
Dim
myCommandAs SqlCommandDim myConnectionAs SqlConnectionDim insertCmdAsStringmyConnection =
New SqlConnection("Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|CustomerInfo.mdf;Integrated Security=True;User Instance=True")insertCmd =
"Insert into CustomerTable Values (@.WorkSheetID, @.Origin, @.DealerName, @.DateCreated, " _&
"@.SalesRep, @.BkupSalesRep, @.FirstName, @.MiddleName, @.LastName, @.Address, @.City, @.State, " _&
"@.Zip, @.HomePhone, @.WorkPhone, @.CellPhone, @.Email, @.County, @.SalesTax, @.SS, @.DOB)"myCommand =
New SqlCommand(insertCmd, myConnection)myCommand.Parameters.Add(
New SqlParameter("@.WorkSheetID", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.WorkSheetID").Value = lblCustWksnum.TextmyCommand.Parameters.Add(
New SqlParameter("@.Origin", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.Origin").Value = lblSaleOrigin.TextmyCommand.Parameters.Add(
New SqlParameter("@.DealerName", Data.SqlDbType.Char))myCommand.Parameters(
"@.DealerName").Value = lblDealerShipName.TextmyCommand.Parameters.Add(
New SqlParameter("@.DateCreated", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.DateCreated").Value = lblDateCreated.TextmyCommand.Parameters.Add(
New SqlParameter("@.SalesRep", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.SalesRep").Value = lblSlsRep.TextmyCommand.Parameters.Add(
New SqlParameter("@.BkupSalesRep", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.BkupSalesRep").Value = lblBkupSlsRep.TextmyCommand.Parameters.Add(
New SqlParameter("@.FirstName", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.FirstName").Value = lblcFirstName.TextmyCommand.Parameters.Add(
New SqlParameter("@.MiddleName", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.MiddleName").Value = lblcMiddleName.TextmyCommand.Parameters.Add(
New SqlParameter("@.LastName", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.LastName").Value = lblcLastName.TextmyCommand.Parameters.Add(
New SqlParameter("@.Address", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.Address").Value = rBuyAddressmyCommand.Parameters.Add(
New SqlParameter("@.City", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.City").Value = rcitymyCommand.Parameters.Add(
New SqlParameter("@.State", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.State").Value = rStatemyCommand.Parameters.Add(
New SqlParameter("@.Zip", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.Zip").Value = rZipmyCommand.Parameters.Add(
New SqlParameter("@.HomePhone", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.HomePhone").Value = lblHnum.TextmyCommand.Parameters.Add(
New SqlParameter("@.WorkPhone", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.WorkPhone").Value = lblWnum.TextmyCommand.Parameters.Add(
New SqlParameter("@.CellPhone", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.CellPhone").Value = lblCnum.TextmyCommand.Parameters.Add(
New SqlParameter("@.Email", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.Email").Value = lblEmailAddres.TextmyCommand.Parameters.Add(
New SqlParameter("@.County", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.County").Value = lblBuyersCounty.TextmyCommand.Parameters.Add(
New SqlParameter("@.SalesTax", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.SalesTax").Value = lblSalesTax.TextmyCommand.Parameters.Add(
New SqlParameter("@.SS", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.SS").Value = lblSSN.TextmyCommand.Parameters.Add(
New SqlParameter("@.DOB", Data.SqlDbType.NVarChar))myCommand.Parameters(
"@.DOB").Value = lblDOB.TextmyCommand.Connection.Open()
TrymyCommand.ExecuteNonQuery()
ShowMessageBox(
Me,"Record Added " & insertCmd)Catch exAs SqlExceptionIf ex.Number = 2627ThenShowMessageBox(
Me,"ERROR: A record already exists with " _&
"the same primary key")ElseShowMessageBox(
Me,"ERROR: Could not add record")EndIfEndTrymyCommand.Connection.Close()
|||I would suggest to use the function .AddWithValue and not Add and set the value separately. I think I had the same problem that you have. I have it working with AddWithValue.
Rumoldus
|||(1) Try specifying the column names too in the INSERT statement as in :
"Insert into CustomerTable(WorkSheetId, Origin,..... ) Values (@.WorkSheetID, @.Origin, @.DealerName, @.DateCreated, " _
&"@.SalesRep, @.BkupSalesRep, @.FirstName, @.MiddleName, @.LastName, @.Address, @.City, @.State, " _
&"@.Zip, @.HomePhone, @.WorkPhone, @.CellPhone, @.Email, @.County, @.SalesTax, @.SS, @.DOB)"
(2) You can simplify your code a little bit by declaring and setting the value for the parameter in 1 line.
myCommand.Parameters.Add(New SqlParameter("@.userid",SqlDbType.int)).Value = 1
No comments:
Post a Comment