Syntax error using INNER JOIN and SqlDataSource with MySQL - asp.net

I am trying to write an update command that joins 2 tables using an SqlDataSource. I have it working with 1 table, but when I put my INNER JOIN syntax in I get thrown an error. It says "My syntax is wrong. Check MySql manual for correct syntax"
Here is my Code from my ASPX page.:
<asp:SqlDataSource ID="AdminSalesmanDetailDS" runat="server"
ConnectionString="<%$ ConnectionStrings:intelliairConnectionString %>"
ProviderName="<%$ ConnectionStrings:intelliairConnectionString.ProviderName %>"
SelectCommand="individual_AddressByIndividualID"
SelectCommandType="StoredProcedure"
UpdateCommand="UPDATE individual SET
FarmName = #FarmName,
FirstName = #FirstName,
MiddleName = #MiddleName,
Address1 = #Address1,
City = #City
INNER JOIN address a ON i.IndividualID = a.IndividualID,
WHERE IndividualID=#IndividualID">
<SelectParameters>
<asp:ControlParameter ControlID="gvSalesman" Name="oIndividualID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="FarmName" ControlId="fvAdminSalesmanDetail$CompanyTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="FirstName" ControlId="fvAdminSalesmanDetail$FirstNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="MiddleName" ControlId="fvAdminSalesmanDetail$MiddleNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="Address1" ControlId="fvAdminSalesmanDetail$Address1TextBox" PropertyName="Text"/>
<asp:ControlParameter Name="City" ControlId="fvAdminSalesmanDetail$cityTextBox" PropertyName="Text"/>
</UpdateParameters>
</asp:SqlDataSource>
UPDATE
I have it working with 2 tables now. However it updates every Individual in the Table. For example: I am trying to update 1 person and I change the first name to Mark. When I click update , it changes everyone in the Database First Name to Mark.
Here is my new Code from my ASPX page.:
<asp:SqlDataSource ID="AdminSalesmanDetailDS" runat="server"
ConnectionString="<%$ ConnectionStrings:intelliairConnectionString %>"
ProviderName="<%$ ConnectionStrings:intelliairConnectionString.ProviderName %>"
SelectCommand="individual_AddressByIndividualID"
SelectCommandType="StoredProcedure"
UpdateCommand="UPDATE individual i
inner join address a
on a.individualID = i.individualID
set
i.FarmName = #FarmName,
i.FirstName = #FirstName,
i.LastName = #LastName,
i.MiddleName = #MiddleName,
i.Phone = #Phone,
i.PhoneExtention = #PhoneExtention,
i.MobilPhone = #MobilPhone,
i.Fax = #Fax,
i.Email = #Email,
a.Address1 = #Address1,
a.Address2 = #Address2,
a.City = #City,
a.State = #State,
a.Zip = #Zip,
a.Country = #Country
where
i.IndividualID = i.IndividualID">
<SelectParameters>
<asp:ControlParameter ControlID="gvSalesman" Name="oIndividualID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="FarmName" ControlId="fvAdminSalesmanDetail$CompanyTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="FirstName" ControlId="fvAdminSalesmanDetail$FirstNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="MiddleName" ControlId="fvAdminSalesmanDetail$MiddleNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="Address1" ControlId="fvAdminSalesmanDetail$Address1TextBox" PropertyName="Text"/>
<asp:ControlParameter Name="City" ControlId="fvAdminSalesmanDetail$cityTextBox" PropertyName="Text"/>
</UpdateParameters>
</asp:SqlDataSource>

You have your JOIN after the SET, and you're not being specific about which table each field is referencing. I think, to use JOIN in an UPDATE, you need syntax more like this:
UpdateCommand=" UPDATE
individual i
INNER JOIN
address a
ON i.IndividualID = a.IndividualID
SET
i.FarmName = #FarmName,
i.FirstName = #FirstName,
i.MiddleName = #MiddleName,
a.Address1 = #Address1,
a.City = #City
WHERE
i.IndividualID=#IndividualID" >
Edit: Based on the update to your question, it looks like you have (in your WHERE clause)
i.IndividualID=i.IndividualID
This is what's causing all your records to be updated (because that statement is always true). As in my above example, you need to have
i.IndividualID=#IndividualID
This way only the row(s) whose ID matches your parameter gets updated (presumably just one).

Related

How to fix below issue ? Stored Procedure

While I am executing below stored procedure it will result a error in my webpage. Error is
Procedure or function 'AuditsReportForLPA' expects parameter '#Division', which was not supplied
Here is asp.net markup:
<asp:SqlDataSource ID="sqlAudits" runat="server"
ConnectionString="<%$ ConnectionStrings:TESTQTYConnectionString %>"
SelectCommand="AuditsReportForLPA" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddlAuditType" Name="AuditType"
PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="ddlDivision" Name="Divison"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="txtDateFrom" Name="dateFrom"
PropertyName="Text" />
<asp:ControlParameter ControlID="txtDateTo" Name="dateTo" PropertyName="Text" />
<asp:ControlParameter ControlID="ddlAuditedBy" Name="name"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
Here is my stored procedure
ALTER PROCEDURE [dbo].[AuditsReportForLPA]
#AuditType NVARCHAR(75),
#Division NVARCHAR(10),
#dateFrom DATETIME,
#dateTo DATETIME,
#name VARCHAR(14)
AS
BEGIN
IF #Division = '003'
BEGIN
SELECT *
FROM dbo.view_LPA_Audits_with_Names
WHERE division = '001' OR division = '002' OR division = '003'
AND auditdate BETWEEN #dateFrom AND #dateTo
AND ISNULL(AuditType, '') LIKE #AuditType
ORDER BY auditdate
END
ELSE
BEGIN
SELECT *
FROM dbo.view_LPA_Audits_with_Names
WHERE division LIKE #Division
AND auditdate BETWEEN #dateFrom AND #dateTo
AND ISNULL(AuditType, '') LIKE #AuditType
ORDER BY auditdate
END
END

search gridview with objectdatasource

I have this procedure for performing the search:
ALTER PROCEDURE dbo.book_serchbook
#BookTitle nvarchar(100) ,
#CategoryName nvarchar (100) ,
#AuthorName nvarchar(100),
#PublisherName nvarchar(100)
AS
SELECT DISTINCT
dbo.BookTable.BookID,
dbo.BookTable.BookCover,
dbo.BookTable.BookPrice,
dbo.BookTable.BookTitle,
dbo.PublisherTable.PublisherName,
dbo.CategoryTable.CategoryName
FROM
BookTable
INNER JOIN
CategoryTable ON CategoryTable.CategoryID = BookTable.CategoryID
INNER JOIN
PublisherTable ON PublisherTable.PublisherID = BookTable.PublisherID
LEFT OUTER JOIN
BookAuthorTable
INNER JOIN
AuthorTable ON AuthorTable.AuthorID = BookAuthorTable.AuthorID
ON BookTable.BookID = BookAuthorTable.BookID
WHERE
(PublisherTable.PublisherName LIKE '%' + #PublisherName + '%') and
(BookTable.BookTitle LIKE '%' + #BookTitle + '%') and
(AuthorTable.AuthorFName + ' ' + AuthorTable.AuthorLName LIKE '%' + #AuthorName + '%') and
(CategoryTable.CategoryName= #CategoryName )
On my ASPX page I use a gridview with ObjectDataSource to display results, the object source code Is :
<asp:ObjectDataSource ID="ObjectDataSource4" runat="server"
DataObjectTypeName="BookDataBaseComponent.BookDetails" OldValuesParameterFormatString="original_{0}"
DeleteMethod="DeleteBook" InsertMethod="InsertBook" SelectMethod="SearchBook"
TypeName="BookDataBaseComponent.BookDB" UpdateMethod="UpdateBook">
<DeleteParameters>
<asp:Parameter Name="BookID" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="booktb" DefaultValue="%" Name="BookTitle"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="%"
Name="CategoryName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="afnbk" DefaultValue="%" Name="AuthorName"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="pubtb" DefaultValue="%" Name="PublisherName"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
My problem: the page doesn't display any results while the and operator between conditions in the where clause is present. When I change it to OR it displays results
And I can't search when I click the search button nothing happens.
Please any help .I really need help

ASP Gridview Select statement not working (GUID)

I'm using ASP.net to use a gridview. The gridview's sql data source is a select statement where ID = a value (a GUID) from a querystring.
However, when I try and preview it, it doesn't show any results. If I change it to a different type (int) of 1, then it works fine and shows results.
If I do the select statement in SQL Server Management Studio (with the GUID), it works fine and shows the results.
Here's the code for the data:
<asp:SqlDataSource ID="SQLDataSourceL" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [FName], [Date] FROM [Table1] WHERE (([FName] = #FName) AND ([Type] = #Type)) ORDER BY [Date] DESC, [FName]">
<SelectParameters>
<asp:QueryStringParameter Name="FName" QueryStringField="id" Type="Object" />
<asp:Parameter DefaultValue="X" Name="Type" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
(I've changed the column names).
Hope you can help.
Try changing the QueryStringParameter to the suitable type, eg:
<asp:QueryStringParameter Name="FName" QueryStringField="id" Type="String" />

GridView SelectCommand missing WHERE at runtime

I've got a GridView. My SelectCommand in the code works if I copy and paste it into SQL Server Management Studio. It executes fine.
If I run the page and click Edit for any row I get the error:
"Incorrect syntax near the keyword 'IS'."
I've tried to see what's going on using SQL Server Profiler. Here's what the SelectCommand looks like and what SQL is receiving...
SelectCommand from supplies.ascx
SELECT some stuff FROM here WHERE (this IS NULL) and (that=1) ORDER BY this DESC
SQL Server Profiler reports
SELECT some stuff FROM here (this IS NULL) and (that=1) ORDER BY this DESC
I didn't put any code here because I'm not really sure what would be relevant and didn't want to load up the post with unnecessary lines of code. Please let me know what you'd like to see to help.
Requested code below. I didn't put everything from the GridView in...It's pretty big. If needed though I can update.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="fldSupReqID"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." AllowSorting="True"
CellPadding="4" ForeColor="#333333" Font-Size="10px">
<RowStyle BackColor="#EFF3FB" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
DeleteCommand="DELETE FROM [tblSupplyRequests] WHERE [fldSupReqID] = #fldSupReqID"
InsertCommand="INSERT INTO [tblSupplyRequests] ([fldManufacturerID], [fldItemID], [fldFeeTypeID], [fldRequestDate], [fldStamp], [fldAddedByUser], [fldBID]) VALUES (#fldManufacturerID, #fldItemID, #fldFeeTypeID, #fldRequestDate, #fldStamp, #fldAddedByUser, #fldBID)"
ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>" SelectCommand="SELECT tblSupplyRequests.fldSupReqID, tblSupplyRequests.fldOrderToShipDate, tblSupplyRequests.fldBID AS BID, tblMerchantIDs.fldMerchantID AS MerchantID, salescontactinfo.sname_of_business AS [Merchant Name], salescontactinfo.scontactname1 AS Contact, salescontactinfo.scontactn1phone1 AS Phone, tblSupplyRequests.fldRequestDate, tblSupplyRequests.fldAddedByUser AS RequestedBy, INVtblManufacturers.fldManufacturerName AS [Term Manuf], INVtblInventoryItems_1.fldItemName AS [Term Model], INVtblInventoryTypes.fldInventoryTypename AS [Item Type], tblSupplyRequests.fldNumItemsRequested AS [Num Items], tblSupplyRequests.fldPaperItemID, tblSupplyRequests.fldPerItemCost, INVtblInventoryItems.fldMiscDesc, tblSupplyRequests.fldPersonCalling, tblSupplyRequests.fldTitlePersonCalling, tblSupplyRequests.fldNotes, salescontactinfo.sstate, tblSupplyRequests.fldManufacturerID, tblSupplyRequests.fldItemID, tblSupplyRequests.fldStamp, tblSupplyRequests.fldOrderToShipDate AS Expr1, tblSupplyRequests.fldOrderToShipBy FROM INVtblInventoryItems INNER JOIN tblSupplyRequests INNER JOIN salescontactinfo ON tblSupplyRequests.fldBID = salescontactinfo.sbusinessid LEFT OUTER JOIN tblMerchantIDs ON salescontactinfo.sbusinessid = tblMerchantIDs.fldBID LEFT OUTER JOIN INVtblManufacturers ON tblSupplyRequests.fldManufacturerID = INVtblManufacturers.fldManufacturerID ON INVtblInventoryItems.fldItemID = tblSupplyRequests.fldPaperItemID LEFT OUTER JOIN INVtblInventoryTypes ON tblSupplyRequests.fldInventoryTypeID = INVtblInventoryTypes.fldInventoryTypeID LEFT OUTER JOIN INVtblInventoryItems AS INVtblInventoryItems_1 ON tblSupplyRequests.fldItemID = INVtblInventoryItems_1.fldItemID WHERE (tblSupplyRequests.fldOrderToShipDate IS NULL) AND (tblMerchantIDs.fldMIDStatusID=1) ORDER BY tblSupplyRequests.fldRequestDate DESC"
UpdateCommand="UPDATE tblSupplyRequests SET fldOrderToShipDate=#fldOrderToShipDate, fldNotes = #fldNotes, fldTitlePersonCalling = #fldTitlePersonCalling, fldPersonCalling = #fldPersonCalling, fldRequestDate = #fldRequestDate WHERE (fldSupReqID = #fldSupReqID)">
<DeleteParameters>
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="fldManufacturerID" Type="Int32" />
<asp:Parameter Name="fldItemID" Type="Int32" />
<asp:Parameter Name="fldFeeTypeID" Type="Int32" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldStamp" Type="DateTime" />
<asp:Parameter Name="fldAddedByUser" Type="String" />
<asp:Parameter Name="fldBID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="fldOrderToShipDate" Type="DateTime" />
<asp:Parameter Name="fldNotes" Type="String" />
<asp:Parameter Name="fldTitlePersonCalling" Type="String" />
<asp:Parameter Name="fldPersonCalling" Type="String" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
And here's what SQL Server Profiler catches...
SELECT tblSupplyRequests.fldSupReqID, tblSupplyRequests.fldOrderToShipDate, tblSupplyRequests.fldBID AS BID, tblMerchantIDs.fldMerchantID AS MerchantID, salescontactinfo.sname_of_business AS [Merchant Name], salescontactinfo.scontactname1 AS Contact, salescontactinfo.scontactn1phone1 AS Phone, tblSupplyRequests.fldRequestDate, tblSupplyRequests.fldAddedByUser AS RequestedBy, INVtblManufacturers.fldManufacturerName AS [Term Manuf], INVtblInventoryItems_1.fldItemName AS [Term Model], INVtblInventoryTypes.fldInventoryTypename AS [Item Type], tblSupplyRequests.fldNumItemsRequested AS [Num Items], tblSupplyRequests.fldPaperItemID, tblSupplyRequests.fldPerItemCost, INVtblInventoryItems.fldMiscDesc, tblSupplyRequests.fldPersonCalling, tblSupplyRequests.fldTitlePersonCalling, tblSupplyRequests.fldNotes, salescontactinfo.sstate, tblSupplyRequests.fldManufacturerID, tblSupplyRequests.fldItemID, tblSupplyRequests.fldStamp, tblSupplyRequests.fldOrderToShipDate AS Expr1, tblSupplyRequests.fldOrderToShipBy FROM INVtblInventoryItems INNER JOIN tblSupplyRequests INNER JOIN salescontactinfo ON tblSupplyRequests.fldBID = salescontactinfo.sbusinessid LEFT OUTER JOIN tblMerchantIDs ON salescontactinfo.sbusinessid = tblMerchantIDs.fldBID LEFT OUTER JOIN INVtblManufacturers ON tblSupplyRequests.fldManufacturerID = INVtblManufacturers.fldManufacturerID ON INVtblInventoryItems.fldItemID = tblSupplyRequests.fldPaperItemID LEFT OUTER JOIN INVtblInventoryTypes ON tblSupplyRequests.fldInventoryTypeID = INVtblInventoryTypes.fldInventoryTypeID LEFT OUTER JOIN INVtblInventoryItems AS INVtblInventoryItems_1 ON tblSupplyRequests.fldItemID = INVtblInventoryItems_1.fldItemID (tblSupplyRequests.fldOrderToShipDate IS NULL) AND (tblMerchantIDs.fldMIDStatusID=1) ORDER BY tblSupplyRequests.fldRequestDate DESC
I hate to say this, but it could just be that ASP.NET is parsing the query incorrectly because of all the nested INNER JOINs that precede it all on one line. I wonder if formatting your SQL would help at all? There is a very cool tool online for neatly formatting your SQL statements.
Here's the formatted version of your SQLDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
DeleteCommand=" DELETE FROM [tblSupplyRequests]
WHERE [fldSupReqID] = #fldSupReqID"
InsertCommand=" INSERT INTO [tblSupplyRequests] ([fldManufacturerID],[fldItemID],[fldFeeTypeID],[fldRequestDate],[fldStamp],[fldAddedByUser],[fldBID])
VALUES (#fldManufacturerID,#fldItemID,#fldFeeTypeID,#fldRequestDate,#fldStamp,#fldAddedByUser,#fldBID)"
ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>"
SelectCommand=" SELECT tblsupplyrequests.fldsupreqid,
tblsupplyrequests.fldordertoshipdate,
tblsupplyrequests.fldbid AS bid,
tblmerchantids.fldmerchantid AS merchantid,
salescontactinfo.sname_of_business AS [Merchant Name],
salescontactinfo.scontactname1 AS contact,
salescontactinfo.scontactn1phone1 AS phone,
tblsupplyrequests.fldrequestdate,
tblsupplyrequests.fldaddedbyuser AS requestedby,
invtblmanufacturers.fldmanufacturername AS [Term Manuf],
invtblinventoryitems_1.flditemname AS [Term Model],
invtblinventorytypes.fldinventorytypename AS [Item Type],
tblsupplyrequests.fldnumitemsrequested AS [Num Items],
tblsupplyrequests.fldpaperitemid,
tblsupplyrequests.fldperitemcost,
invtblinventoryitems.fldmiscdesc,
tblsupplyrequests.fldpersoncalling,
tblsupplyrequests.fldtitlepersoncalling,
tblsupplyrequests.fldnotes,
salescontactinfo.sstate,
tblsupplyrequests.fldmanufacturerid,
tblsupplyrequests.flditemid,
tblsupplyrequests.fldstamp,
tblsupplyrequests.fldordertoshipdate AS expr1,
tblsupplyrequests.fldordertoshipby
FROM invtblinventoryitems
INNER JOIN tblsupplyrequests
INNER JOIN salescontactinfo
ON tblsupplyrequests.fldbid = salescontactinfo.sbusinessid
LEFT OUTER JOIN tblmerchantids
ON salescontactinfo.sbusinessid = tblmerchantids.fldbid
LEFT OUTER JOIN invtblmanufacturers
ON tblsupplyrequests.fldmanufacturerid = invtblmanufacturers.fldmanufacturerid
ON invtblinventoryitems.flditemid = tblsupplyrequests.fldpaperitemid
LEFT OUTER JOIN invtblinventorytypes
ON tblsupplyrequests.fldinventorytypeid = invtblinventorytypes.fldinventorytypeid
LEFT OUTER JOIN invtblinventoryitems AS invtblinventoryitems_1
ON tblsupplyrequests.flditemid = invtblinventoryitems_1.flditemid
WHERE ( tblsupplyrequests.fldordertoshipdate IS NULL )
AND ( tblmerchantids.fldmidstatusid = 1 )
ORDER BY tblsupplyrequests.fldrequestdate DESC"
UpdateCommand=" UPDATE tblsupplyrequests
SET fldordertoshipdate = #fldOrderToShipDate,
fldnotes = #fldNotes,
fldtitlepersoncalling = #fldTitlePersonCalling,
fldpersoncalling = #fldPersonCalling,
fldrequestdate = #fldRequestDate
WHERE ( fldsupreqid = #fldSupReqID )" >
<DeleteParameters>
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="fldManufacturerID" Type="Int32" />
<asp:Parameter Name="fldItemID" Type="Int32" />
<asp:Parameter Name="fldFeeTypeID" Type="Int32" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldStamp" Type="DateTime" />
<asp:Parameter Name="fldAddedByUser" Type="String" />
<asp:Parameter Name="fldBID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="fldOrderToShipDate" Type="DateTime" />
<asp:Parameter Name="fldNotes" Type="String" />
<asp:Parameter Name="fldTitlePersonCalling" Type="String" />
<asp:Parameter Name="fldPersonCalling" Type="String" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
Note: if your queries in the SQLDataSource are getting this complex, you may want to consider moving this logic into a class / data access layer for future maintainability. Having said that, I understand that sometimes you are stuck with what you have for the time-being =) Good luck!

SWL Error Function has too many arguments specified

I am using ASP.NET 3.5 and SQL Server 2008.
I have a SQLDataSource & Gridview. I am trying to update 2 tables at the same time using a stored procedure in SQL.
SQLDatasource is passing 7 parameters.
5 parameters that the stored procedaure needs, Return value & StudentID.
Not sure if the error is in my SQLDatasorce or my stored procedure.
Here's my ASPX Code:
<asp:SqlDataSource ID="sqldsUserLoginNLevels" runat="server"
ConnectionString="<%$ ConnectionStrings:QuizStarConnectionString %>"
SelectCommand="SELECT UserLogins.StudentID, UserLogins.StudentName, UserLogins.UserID,
UserLogins.Password, UserLevels.GrammarStart, UserLevels.GrammarCurrent,
UserLevels.MathStart, UserLevels.MathCurrent
FROM UserLogins
INNER JOIN UserLevels ON UserLogins.StudentID = UserLevels.StudentID"
DeleteCommand="DELETE FROM [UserLogins] WHERE [StudentID] = #original_StudentID"
InsertCommand="INSERT INTO [UserLogins] ([StudentName], [UserID], [Password])
VALUES (#StudentName, #UserID, #Password)"
UpdateCommand="UpdateUserLoginsAndUserLevels"
UpdateCommandType="StoredProcedure" >
<DeleteParameters>
<asp:Parameter Name="original_StudentID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="StudentName" Type="String" />
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="GrammarStart" Type="String" />
<asp:Parameter Name="MathStart" Type="String" />
<asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="StudentName" Type="String" />
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="Password" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
My Stored Procedure is:
ALTER PROCEDURE [dbo].[UpdateUserLoginsAndUserLevels] (
#StudentName VARCHAR(50),
#UserID NCHAR(10),
#Password NCHAR(10),
#GrammarStart NCHAR(10),
#MathStart NCHAR(10))
AS
DECLARE #StudentID INT;
BEGIN Transaction
BEGIN TRY
SELECT * From UserLogins
Where StudentID = #StudentID
UPDATE UserLogins
SET
StudentName= #StudentName,
UserID = #UserID,
Password = #Password
Where StudentID = #StudentID
UPDATE UserLevels
SET
GrammarStart= #GrammarStart,
MathStart = #MathStart
FROM UserLevels
INNER JOIN UserLogins ON UserLogins.StudentID = UserLevels.StudentID
WHERE (UserLevels.StudentID = #StudentID)
END TRY
BEGIN CATCH
DECLARE #ErrorMessage NVARCHAR(4000), #ErrorSeverity INT
-- Assign variables to error-handling functions that
-- capture information for RAISERROR.
SELECT #ErrorMessage = ERROR_MESSAGE(), #ErrorSeverity = ERROR_SEVERITY()
-- Rollback the failed transaction
ROLLBACK;
-- Raise an error: with the original error information.
RAISERROR(#ErrorMessage, #ErrorSeverity, 1);
END CATCH
COMMIT Transaction;
Have't figured how to post code yet. Sorry.
Make sure you are not double adding parameters. Since you are adding them in the aspx page you do not need to add them in your code behind.
For example if your code behind has this in it:
sqldsUserLoginNLevelsUserID.UpdateParameters.Add(new Parameter("UserID ", TypeCode.Int32));
It could explain your error.
If you need to set the value from code behind do it like this:
sqldsUserLoginNLevelsUserID.UpdateParameters["UserID "].DefaultValue = "1";

Resources