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
Related
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
I have a grid that has some date values. What I like to do is to convert those date values into UTC date format and then enter that inside the table.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KruSQL %>"
UpdateCommand="UPDATE [dbo].[Microbiology] SET RoomNum=#RoomNum, CollDate=#CollDate, WaterFixure=#WaterFixure Where ID=#ID">
<UpdateParameters>
<asp:Parameter Name="RoomNum" Type="String" />
<asp:Parameter Name="WaterFixure" Type="String" />
<asp:Parameter Name="CollDate" Type="DateTime" />
</UpdateParameters>
My qustion is how can I make use of :
UpdateCommand="UPDATE [dbo].[Microbiology] SET RoomNum=#RoomNum, CollDate=#CollDate, WaterFixure=#WaterFixure Where ID=#ID"
and still update the value of CollDate to UTC. Is there anyway to do this in the code behind and still make us of the UpdateCommand
try this :
UpdateCommand="UPDATE [dbo].[Microbiology] SET RoomNum=#RoomNum, CollDate=DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), #ColDate), WaterFixure=#WaterFixure Where ID=#ID"
convert Date to UTCDate :
DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), YOUR_DATE)
I am trying to filter a gridview to show orders between specific dates. I managed to make it work but it does not show the records for the Date To. It only shows the between of that dates. The records that exist in Date from shows up...
<asp:EntityDataSource ID="EDS_Orders" runat="server" EnableUpdate="true" EnableFlattening="False" OrderBy="it.Order_date ASC"
ConnectionString="name=Bohemian1Entities" DefaultContainerName="Bohemian1Entities" EntitySetName="t_customer_orders"
Where="it.UserName is not null and (it.Order_date Between #DateFrom AND #DateTo) AND (it.UserName Like '%' + #UserName + '%') " >
<WhereParameters>
<asp:ControlParameter ControlID="ddlDateFrom" Name="DateFrom"
Type="DateTime" DefaultValue="%"/>
<asp:ControlParameter ControlID="ddlDateTo" Name="DateTo"
Type="DateTime" DefaultValue="%"/>
<asp:ControlParameter ControlID="ddlCustomers" Name="UserName" PropertyName="Text"
Type="String" DefaultValue="%"/>
</WhereParameters>
</asp:EntityDataSource>
Try to rewrite Where clause as below:
Where="it.UserName is not null and (CAST(it.Order_date AS DATE) Between #DateFrom AND #DateTo)
AND (it.UserName Like '%' + #UserName + '%')"
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).
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";