Hey, I have a search form with a selectbox. This selectbox contains the columnnames.
I want when I put a text in a textbox and select a value in the selectbox and click submit that it search database.The Columnnames I put in a session.
If you see I have put in the querystring as columnname @sescolumn which I have initialised as asp:sessionparameter.
But it gives no results. When I put @sescolumn between [] like normal columnnames are it doesn't work also.
Can someon put my on the right path?
<asp:SqlDataSource ID="Database_ecars" runat="server" ConnectionString="<%$ ConnectionStrings:connectionstring %>"
SelectCommand="SELECT [AutoID], [Merk], [Kleur], [Type], [Autotype], [prijs], [Zitplaatsen], [Afbeelding1], [Afbeelding2], [Afbeelding3], [Afbeelding4] FROM [Auto] where @sescolumn like @seskeyword and [AutoID] not in (select [AutoID] from [verhuring] where [StartVerhuur] >= @sesdatefrom and [Eindeverhuur] <= @sesdatetill)" >
<SelectParameters>
<asp:SessionParameter Name="sesdatefrom" SessionField="datefrom" Type="Decimal" />
<asp:SessionParameter Name="sesdatetill" SessionField="datetill" Type="Decimal" />
<asp:SessionParameter Name="seskeyword" SessionField="keyword" Type="string" />
<asp:SessionParameter Name="sescolumn" SessionField="columnname" Type="string" />
</SelectParameters>
</asp:SqlDataSource>
Hi, I have to choose a particular column from a table whenever a condition met. That means i have to use the column in the select query whenever the condition met otherwise i have to create a dummy column with the same column name. I tried to use the following sample query. Eg: Create table temp (test_id int, test varchar(100))
Declare @var varchar(100) Set @Var='Hi' Select case when @Var='HI' then "None" else Test_new End as Test from Temp
But it throw error as "Invalid column 'Test_new' "
As per my situation the Test_new column will be available in temp table whenever the condition is not met.So when @var<>'HI' i have to get the details of the test_new column otherwise i have to create a dummy column with the same name.
Here is the issue I'm having. I am writing a stored procedure that takes a couple of parameters. Each one is the value within a specific column in one table (i.e., @part = 'o-ring' or @sub_assembly = 'hydraulic ram'). Needless to say, the columns form a hierarchy. What I am trying to achieve is to allow the user to specify one of the parameters and get a count for all records where the specified value is in the corresponding column. So, if the user puts in the parameter @part = 'o-ring', I want it to know that the where clause for the select statement should look for o-ring in the part column and not the sub_assembly column. Here is what I am trying to do, which isn't working.
IF(@sub_assembly = NULL) BEGIN IF(@part = NULL) BEGIN PRINT 'This is an error. You must have at least a part' END ELSE BEGIN SET @querycolumn = 'Part' SET @queryvalue = @part END END ELSE BEGIN SET @querycolumn = 'SubAssembly' SET @queryvalue = @sub_assembly END
SELECT SubAssembly, Part, COUNT(RecordID) FROM Table WHERE @querycolumn = @queryvalue GROUP BY SubAssembly, Part ORDER BY SubAssembly, Part
The problem is that I'm getting an error when I try to use @querycolumn to supply the column name to the WHERE clause. Any ideas or suggestions?
NET 2.0 I am using Visual Studio Express 2005 for database web developement. I have created a database with 5 tables. Two are associative tables. They are SoftwarePK SoftwareID Title SoftwareSolutionFK SoftwareIDFK SolutionID SolutionPK SolutionID Title CategorySolutionFK CategoryFK Solution Category PK Category Title Criteria for a search with three sources of input into a SqlDataSource attached to a FormView for paged out. The following are the Search Criteria input sources:1) ListBox in Multiple Selection Mode2) CheckBoxList with Mutiple checks posible2) TextBox with key word search in Title. Each Solution has 0 or many Categories and 0 or many Software. When the records are entered in the database, the associative information for Categories and Software are populated to filter thereturned values. In NET 1.1, I would create a search string like the following in code behind by looping through the CheckBoxList and ListBox finally adding the TextBox: SELECT Solution.SolutionID, Solution.Title FROM SolutionWHERE Solution.SolutionID IN ('2','3','5') AND Solution.Title LIKE '%Math%' I am unable to update the SelectCommand in the ASPX page. However, when I use the I have used theSystem.Web.UI.WebControls.SqlDataSources"SelectQuery Builder"I receive the following in the Source for ASPX: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT Solution.SolutionID, Solution.Title FROM Solution INNER JOIN CategorySolution ON Solution.SolutionID = CategorySolution.SolutionID INNER JOIN SoftwareSolution ON Solution.SolutionID = SoftwareSolution.SolutionID"> <SelectParameters> <asp:ControlParameter ControlID="CheckBoxList1" DefaultValue="%" Name="CategoryID" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="ListBox1" DefaultValue="%" Name="SoftwareID" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="txtTitleSearch" DefaultValue="%" Name="Title" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource> I receive duplicate records and not sure if the code generated accesses the Mutiple Selected values in the CheckBoxList1 and ListBox1.Question: 1) If the SelectQuery generator will not access multiple selected values from the CheckBoxList1, how can I use code behind to replaceSelectCommand in the ASPX page?2) What is the best solution for using the CheckBoxList1, ListBox1, and TextBox for filtering my results? Sample code, references to solutions, corrections on logic, a new approach, how to use the wizard correctly would all be greatly appreciated.3) Can Multiple Selection Controls be use with a SqlDataSource SELECT Command?Thanks for your time,Sincerely,Unhistoric
I have a listbox and SqlDataSource. I am not sure how to take the multiple value that are selected in listbox and use it to generate a sqlquery.Below I have shown that if I hard code it in the Command statement it works but I not sure how to take it from a variable or the listbox. ---------------------------------------------------------- <asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name" SelectionMode="Multiple" Width="341px"></asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT classifieds_Ads.Id, classifieds_Ads.MemberId, classifieds_Ads.CategoryId, classifieds_Ads.Title, classifieds_Ads.Description, classifieds_Categories.Name, classifieds_Ads.Price, classifieds_Ads.Location, classifieds_Ads.ExpirationDate, classifieds_Ads.DateCreated FROM classifieds_Ads INNER JOIN classifieds_Categories ON classifieds_Ads.CategoryId = classifieds_Categories.Id WHERE ([Name] IN ('ALASKA','alabama'))"> <SelectParameters> <asp:ControlParameter Name="Name" ControlID="listbox1" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> --------------------------------------------------------
I'm working on a script to convert data from one software packageto another. Greatly simplified, it looks something likecreate procedure import_widget asbegininsert into our_widget (foo, bar)select baz, quux from their_db.dbo.their_widgetendgoThe problem is that the name of the source database varies fromone system to another, so I want to pass the database name as aparameter. I think I could do the following, but is there abetter way to go about it?create procedure import_widget (@db_name sysname) asbeginexec 'create view their_widget as select * from '+ @db_name + '.dbo.their_widget'insert into our_widget (foo, bar)select baz, quux from their_widgetdrop view their_widgetendgo
Hi, I need to write a report which will run based on the user's input for Server Group. Meaning, if the user wants the report to be run for one say, UAT group, the report (and therefore the stored procedure) should be executed against UAT server. Or, if the user wants it to be run on the Production machine, the stored procedure should be executed on the Production Server. Assume that both UAT and Production servers are in the same domain to rule out any authentication issue.
I think one way of doing it is to create a linked server on one server which we use to connect via the Report Manager. So, whatever Server Group is selected based on that the SP will be executed on that respective Server Group's Server, since in the query we will have given full names of the tables that we use.
But, I strongly suspect, that having linked servers will not be accepted since it requires that the server owners maintain that. So, I was thinking if there is any other way of achieving this. If anyone knows, please help me with this.
I've got a cube in SSAS 2205 with some financial measures that I want to appear conditionally in an MDX query. Here's what I mean...
The cube measures I'm interested in are actual revenue, forecast revenue and budget revenue. The dimension I'm reporting across is the [Time].[month] member. The report I'm trying to create with this query has each month across the top. But the headers show actual revenue if the current reporting month is on or before the month in question. For future months, we show the forcast revenue if there is any. For any other future revenue, we show the budget measures. So a sample report for April would have columns like...
Code SnippetJanuary February March April May June July August September Actual Actual Actual Actual Forecast Forecast Forecast Budget Budget
I need to conditionally bring back the right measure and have the measure name (e.g., column header) indicate if it's an actual, forecast or budget value.
I Hope someone can help me out with this problem.. its pretty NB.
I have a pair of multivalued parameters. So, parent and child... the child needs to get its selection based on the selection made by the user on the parent parameter ( the child parameter is hidden).
Fictional values: Parent Parameter: SelectAll, ALL , 1 , 2 Child Parameter: Home, Work, Play
If user selects "ALL" from the parent parameter I need Home and Play selected.
My idea was this: =iif(Parameters!Parent.Value(1) = "All","Home,Play") <-- in Available values.
However, the dataset that reads this value does not like the coma delimited string. This dataset is a cube created dataset, reading the child parameter.
Any help is greatly appreciated. Kind Regards, Neil
I am writing a package where the user uploads a flat file to a web folder. I need to automate this package to run everytime it sees a new file.
How can I implement this?
Can I make a call to a package or a sql server job to run from .net 2.0?
Do I need to use a service broker to look for a new file and run the package or a stored proc....I am looking for an async process where user doesnt have to wait for the package to run as it involves data validation of flat file and its huge...
Does anyone know if there is a way to dynamically set the chart type (i.e. pie, line, column, etc.) for your report in SSRS? I want the customer to be able to chose which type of chart they'd like to see.
I've looked all over the Internet and can't find anything.
Any help would be appreciated. Alan
Clarification: I guess I should clarify a little. I am using an ASP.NET 2.0 page written in C# and using a ReportViewer control.
More Clarification: The ReportViewer displays an rdlc.
suppose i have a table penalties with ticket_number, ticket_start_date datetime, ticket_end_date datetime
There are many records of same ticket_number.example: ticket_number ticket_start_date ticket_end_date 75 2/1/03 3/2/03 75 2/4/03 5/4/03
34 2/1/03 3/3/04 34 3/4/04 3/3/05
I want to write a query which will: 1. select the ticket_number which is not active as of today in case of ticket_number 75 it is closed so I want to print it in report
in case of 34 it was closed but now opened, so i don't want in my report.
set @myCursor = CURSOR FAST_FORWARD for select distinct ticket_number, ticket_start_date, ticket_end_date from penalties where ticket_end_date <= @Today
open @myCursor fetch next from @myCursor into @colA, @colB, @colC
while @@fetch_status=0 begin print @colA print @colB print @colC fetch next from @myCursor into @colA, @colB, @colC end
close @myCursor deallocate @myCursor
GO
-- ============================================= -- example to execute the store procedure -- ============================================= EXECUTE simpleTest GO -------------
however this gives closed tickets but multiple records. I want only the last record details of the ticket_number. I tried last(ticket_number) in my query, but it doesn't affect. Please suggest! thanks. I am using MS SQL server.
I have one table with 6 columns (Entrance1,Exit1,Entrance2,Exit2,Entrance3,Exit3). This columns can take null values. I want to select just the last one of this columns that is not null.
Hello, Has anyone used/fiqured out how to set one of the properties below to a variable with a dynamic database. <asp:SqlDataSource ID="Sql_Imports" runat="server" selectcommand='EXEC <%# Session("CompanyDB") %>..IMPORT_S' ConnectionString=""></asp:SqlDataSource> You would have thought that Microsoft would have allowed catalog/database on this command. Thanks.
Ok, here's my situation. I have a dynamic page that accepts a "type" query string. This type query string is the name of a table I want to display on the page in the GridView. Creating a different SqlDataSource/Strongly typed class for every type isn't possible because I need to make this flexible for future updates. So therefor I basically need to be able to Sort, Page, Edit and Delete with the Grid View without knowing the table name at compile-time. Any help is appreciated, Thanks!
I got your email address from your web cast. I really enjoyed the web cast and found it to be very informative.
Our company is planning to use SSIS (VS 2005 / SQL Server 2005). I have a quick question regarding the product. I have looked for the information on the web, but was not able to find relevant information.
We are getting Source data from two of our client in the form of Excel Sheet. These Excel sheets Are generated using reporting services. On examining the excel sheet, I found out that the name Of the columns contain data itself, so the names are not static such as Jan 2007 Sales, Feb 2007 Sales etc etc. And even the number of columns are not static. It depends upon the range of date selected by the user.
I wanted to know, if there is a way to import Excel sheet using Integration Services by defining the position Of column, instead of column name and I am not sure if there is a way for me to import excel with dynamic Number of columns.
Your help in this respect is highly appreciated!
Thanks,
Hi Anthony, I am glad the Web cast was helpful.
Kamal and I have both moved on to other teams in MSFT and I am a little rusty in that area, though in general dynamic numbers of columns in any format is always tricky. I am just assuming its not feasible for you to try and get the source for SSIS a little closer to home, e.g. rather than using Excel output from Reporting Services, use the same/some form of the query/data source that RS is using.
I suggest you post a question on the SSIS forum on MSDN and you should get some good answers. http://forums.microsoft.com/msdn/showforum.aspx?forumid=80&siteid=1 http://forums.microsoft.com/msdn/showforum.aspx?forumid=80&siteid=1
OK so I need to use a dynamic SQL statement in a SqlDataSource object because I need to pass in the column name. I'm having trouble accounting for the apostophes I have to interpret literals within the statement. This is connecting to an Oracle database. This is what I originally tried... <asp:SqlDataSource ID="SqlDataSourceMine" runat="server" ConnectionString="<%$ ConnectionStrings:My_Connection_String %>" ProviderName="<%$ ConnectionStrings:My_Connection_String.ProviderName %>" SelectCommand="SELECT m.YIE, :selecteditem, m.ENDTIME FROM MyMAP.MAP_M_SUM m WHERE (m.GROUPID LIKE 'YC%' AND m.GROUPID NOT LIKE 'YCX%' AND m.ENDTIME >= SYSDATE-14)"> <SelectParameters> <asp:ControlParameter Name="selecteditem" ControlID="itemlabel" PropertyName="Text" Type="String" /> </SelectParameters></asp:SqlDataSource> And the second column returned as :selecteditem for the column name and the value of itemlabel.text (what I wanted to be the column that was queried) as the value in each of the rows of that column. So I tried dynamic SQL to put the value of itemlabel.txt as the column to be queried, but I'm not sure how to get the query to read the literals. How can I accomplish this? <asp:SqlDataSource ID="SqlDataSourceMine" runat="server" ConnectionString="<%$ ConnectionStrings:My_Connection_String %>" ProviderName="<%$ ConnectionStrings:MY_Connection_String.ProviderName %>" SelectCommand="EXEC('SELECT m.YIE, '+selectedbin+', m.ENDTIME FROM MMAP.MAP_M_SUM m WHERE (m.GROUPID LIKE '+paramlike+' AND m.GROUPID NOT LIKE '+paramnotlike+' AND m.ENDTIME >= SYSDATE-14)')"> <SelectParameters> <asp:ControlParameter Name="selectedbin" ControlID="binlabel" PropertyName="Text" Type="String" /> <asp:ControlParameter Name="paramlike" ControlID="Label1" PropertyName="Text" Type="String" /> <asp:ControlParameter Name="paramnotlike" ControlID="Label2" PropertyName="Text" Type="String" /> </SelectParameters></asp:SqlDataSource> This errors to "illegal variable name" Can someone help me out please? Thanks a lot. -steve
I have a datasource on my ASP.NET 2.0 control I want to make dynamic. I have 6 different connection strings in my web.config file and want to change the connection with the selection in dropdownbox. Here is my VB code:Protected Sub GetDatabase(ByVal intDb As Integer) Select Case intDb
Case 1 ' Americas srcCustomers.ConnectionString = "RWSqlServer" Exit Sub Case 2 ' Asia srcCustomers.ConnectionString = "SGSqlServer" Exit Sub Case 3 ' Australia srcCustomers.ConnectionString = "SYSqlServer" Exit Sub Case 4 ' Canada srcCustomers.ConnectionString = "MSSqlServer" Exit Sub Case 5 ' EMEA srcCustomers.ConnectionString = "NCSqlServer" Exit Sub Case 6 ' NE srcCustomers.ConnectionString = "RUSqlServer" Exit Sub End Select End SubProtected Sub ddlBusinessUnit_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If (ddlBusinessUnit.SelectedIndex = 0) Then panUser.Visible = False panDistributor.Visible = False panEndUser.Visible = False GetDatabase(ddlBusinessUnit.SelectedIndex) lblDb.Text = ddlBusinessUnit.SelectedIndex.ToString Else
panUser.Visible = True End If End Sub Here is my ASP.NET code:<asp:SqlDataSource ID="srcCustomers" runat="server" SelectCommand="SELECT cm_addr + ' - ' + cm_sort AS [name], cm_addr, cm_sort FROM cm_mstr WHERE cm_type <> 'I'"> </asp:SqlDataSource><asp:DropDownList ID="ddlBusinessUnit" runat="server"AutoPostBack="True" OnSelectedIndexChanged="ddlBusinessUnit_SelectedIndexChanged"> <asp:ListItem Value="" Text="Select One"></asp:ListItem> <asp:ListItem Value="1" Text="Americas"></asp:ListItem> <asp:ListItem Value="2" Text="Asia"></asp:ListItem> <asp:ListItem Value="3" Text="Australia"></asp:ListItem> <asp:ListItem Value="4" Text="Canada"></asp:ListItem> <asp:ListItem Value="5" Text="EMEA"></asp:ListItem><asp:ListItem Value="6" Text="NE"></asp:ListItem> </asp:DropDownList> What am I missing? Do I need to reference the whole connection string or is there a way I can reference the "NAME" id in the web.config file for the connection string?
Good morning.I'm writing an application that allows users to generate Personal Leave requests and route them to their managers.I'm using the integrated Windows Authentication, so I'm able to get the user's username from HttpContext.Current.User.Identity.Name.How do I dynamically generate the SelectCommand? Right now, I do:Dim strQuery As String = "SELECT * FROM [tblPLRequest] WHERE employee = '" & strUsername & "'"to get the query I want, but when I set my SelectCommand to that, it thinks it's a stored procedure (and can't find it).Am I going about this in the completely wrong way?Thanks.
I have a GridView (that uses SqlDataSource1) and a Dropdownlist. Depending upon the value selected on the DropDownList I need to select different stored procedures for the gridview. The problem is that I can do it without taking SqlDataSource1 by using DataSet or DataTable. But, I need to Use SQLDataSource1 for easy way of Header SORTING. So, is there any way to change the SQLDatasource1.SELECT Command dynamically. So that, I can use different queries for the Single DataGrid. I have attached the sample code of the SqlDataSource1 I'm using. I need to change the Command i.e. SelectCommand="usp_reports_shortages" to "usp_reports_shortagesbyID" and "usp_reports_shortagesbyDate" depending on the value selected in the dropdownlist. So, is there any way to do this????<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTDrivercommunication %>"
I am trying to implement an "advanced search" feature on my ASP.NET 2.0 web form. I have a GridView control and a SqlDataSource. The SqlDataSource control successfully retrieves data when the SelectCommand attribute is set in the aspx page. I need to make it so when a user clicks on a button, it can take a value from a text box and use it in the WHERE clause. I have tried setting the SelectCommand programmatically and then DataBinding but it never accepts the new SelectCommand. What can I do to fix this?
Consider the below code: I am trying to find a way so that my select statement (which will actually be used to insert records) can randomly place values in the Source and Type columns that it selects from a list which in this case is records in a table variable. I dont really want to perform the insert inside a loop since the production version will work with millions of records. Anyone have any suggestions of how to change the subqueries that constitute these columns so that they are randomized?
SET NOCOUNT ON
Declare @RandomRecordCount as int, @Counter as int Select @RandomRecordCount = 1000
Declare @Type table (Name nvarchar(200) NOT NULL) Declare @Source table (Name nvarchar(200) NOT NULL) Declare @Users table (Name nvarchar(200) NOT NULL) Declare @NumericBase table (Number int not null)
Set @Counter = 0
while @Counter < @RandomRecordCount begin Insert into @NumericBase(Number)Values(@Counter) set @Counter = @Counter + 1 end
Insert into @Type(Name) Select 'Type: Buick' UNION ALL Select 'Type: Cadillac' UNION ALL Select 'Type: Chevrolet' UNION ALL Select 'Type: GMC'
Insert into @Source(Name) Select 'Source: Japan' UNION ALL Select 'Source: China' UNION ALL Select 'Source: Spain' UNION ALL Select 'Source: India' UNION ALL Select 'Source: USA'
Insert into @Users(Name) Select 'keith' UNION ALL Select 'kevin' UNION ALL Select 'chris' UNION ALL Select 'chad' UNION ALL Select 'brian'
select 1 ProviderId, -- static value '' Identifier, '' ClassificationCode, (select TOP 1 Name from @Source order by newid()) Source, (select TOP 1 Name from @Type order by newid()) Type
Hi there, I am a new member of this site and I am not very much aware of T-sql's working. My question is what if I need to get one column's data to be the heading of another column. To be very exact I have a school's database. The table I am talking about is of the results of students. The table contains Student ID, Subject ID, Total marks of the subject, Marks obtained in the subject. Now I want to print a report by generating data from this table. Right now the data is something like this StuID - - - SubID - - - -Tot - - -Obt 1 - - - - - - -1 - - - - - - -50 - - - 38 1 - - - - - - -2 - - - - - - -50 - - - 41 1 - - - - - - -3 - - - - - - -50 - - - 42 1 - - - - - - -4 - - - - - - -50 - - - 40 2 - - - - - - -1 - - - - - - -50 - - - 35 2 - - - - - - -2 - - - - - - -50 - - - 40 2 - - - - - - -3 - - - - - - -50 - - - 42 2 - - - - - - -4 - - - - - - -50 - - - 41
StudentID and SubjectID fields are related to other tables so I can get the names from there but when I need the report I need the data in the form of StuID - Sub 1 - - - Sub 2 - - - Sub 3 - - - -Sub4 1 - - - - 38 - - - - - - 41 - - - - - - 42 - - - - - - 40 2 - - - - 35 - - - - - - 40 - - - - - - 42 - - - - - - 41
The Subjects can be different for different students so the query should be dynamic instead of hard coding the names of the subjects. I hope I am clear with my question. The subjectIDs or their names will become the headings and they will contain the obtained marks for that subjects in their columns just for the reports. I have also checked the PIVOT function but was not able to do what I wanted. Thanks.
Let's say... the sqldatasource has 3 columns: TableKey(int), TableName(string) and StartDate(datetime) and i'm writing a method to return the data type based on the column name.. for example: GetDataType("StartDate") should return "datetime"...what should i do?
Hi,I have an updatable DataGrid linked to a SQLDataSource in a web site developed using VS2005. Update works fine unless a value in the existing row is Null. Only one column in the database allows nulls.Putting a debug stop in the SqlDataSource1_Updating event, I checked the parameter value in the Immediate window and got the following result:?e.Command.Parameters(16){System.Data.SqlClient.SqlParameter}System.Data.SqlClient.SqlParameter: {System.Data.SqlClient.SqlParameter}DbType: Int32 {11}Direction: Input {1}IsNullable: FalseParameterName: "@original_FiresolveJobNo"Size: 0SourceColumn: ""SourceColumnNullMapping: FalseSourceVersion: Current {512}Value: NothingIs there a property I can set to generate a suitable Null check clause for the Update statement?Many Thanks,Keith.
Not sure if this is the correct forum, but I 'm having problems retrieving a sqldatasource's asp:control parameter values from a selected row (during edit) in a gridview to update a record thru a stored procedure. The stored procedure is pretty intense, so I'd like to keep it in SQL if possible instead of creating the generic "update table set ..." that I see in most examples. It seems as if I can't get the propertyname right or something because it keeps giving me a "Procedure or function XX has too many arguments specified error". Maybe the DataKeyNames is not right?? I've tried just passing one parameter (ProductID-same as DataKeyNames) using "SelectedValue" as propertyname and still get the same. It's got to be something very simple, but I'm at a loss. All parameters are spelled the same in the sp (with an added "@" at start) as in the asp:controlparameters. Here's the gridview (asp.net 2.0 connecting to SQL Server 2005): <asp:GridView ID="gvLoadEditProductPrices" runat="server" AutoGenerateColumns="False" AllowSorting="True" DataSourceID="SqlDataSource1" DataKeyNames="ProductID"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="ProductID" HeaderText="ProductID" HeaderStyle-BackColor="white" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" ReadOnly="True" /> <asp:BoundField DataField="ProductCat" HeaderText="ProductCat" SortExpression="ProductCat" ReadOnly="True" /> <asp:BoundField DataField="VarRate" HeaderText="VarRate" SortExpression="VarRate" /> <asp:BoundField DataField="loadid" HeaderText="loadid" InsertVisible="False" ReadOnly="True" SortExpression="loadid" /> <asp:BoundField DataField="loadamount" HeaderText="loadamount" SortExpression="loadamount" ReadOnly="True" /> <asp:BoundField DataField="ProductCol" HeaderText="ProductCol" SortExpression="ProductCol" ReadOnly="True" /> <asp:BoundField DataField="PageID" HeaderText="PageID" SortExpression="PageID" ReadOnly="True" /> </Columns> </asp:GridView> and the sqldatasource's info: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MARSProductEditor %>" ProviderName="System.Data.SqlClient" SelectCommand="spGetLoadEditProductPrices" SelectCommandType="StoredProcedure" UpdateCommand="spUpdateProductPrices" UpdateCommandType="StoredProcedure" > <UpdateParameters> <asp:ControlParameter Name="ProductID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("ProductID")></asp:ControlParameter> <asp:ControlParameter Name="LoadID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("LoadID")></asp:ControlParameter> <asp:ControlParameter Name="PageID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("PageID")></asp:ControlParameter> <asp:ControlParameter Name="ProductCol" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("ProductCol")></asp:ControlParameter> <asp:ControlParameter Name="NewRate" Type="Double" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("NewRate")></asp:ControlParameter> </UpdateParameters> <SelectParameters> <asp:ControlParameter ControlID="ddlEstLoadsPerAcre" Name="LoadID" PropertyName="SelectedValue" Type="Int32" /> <asp:ControlParameter ControlID="txtEditType" Name="PageName" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource>
Hello,I'm still extremely novice to SQL and I've tried googling how to produce this result but I've been encountering a lot dynamic sql commands which isn't exactly what I want. If this is an ignorant question I do apologize but heres my scenario: I have a table with columns of the day, for instance: Monday_hasData (bit)Monday_DataAnd what I want to do is essentially pass in "Monday" as a parameter and rather than doing an If statement on each row, I would like to just like to do something like assign @dayCheck + "_hasData" to a variable and then use @dayCheck as part of my query. Is this possible or am I going to have to have 7 cases? Thank you for any input,Chance
Hi All I want to rename the column name by using the dynamic value as like declare @name as varchar(12) set @name='ss' sp_rename 'dbo.employees.id3',@name, 'COLUMN'; go but it shows the error Incorrect syntax near 'sp_rename'. any idea?
Hi is possible to create dynamic column name example Declare @StartDate as dateTime Select @StartDate = '2004-06-05'
select SUM(Case When table1_date BETWEEN dateadd(day,-6,@StartDate) and @StartDate then 1 else 0 end)AS [dateadd(day,-6,@StartDate)], SUM(Case When table1_date BETWEEN dateadd(day,-13,@StartDate) and dateadd(day,-7,@StartDate) then 1 else 0 end)AS [dateadd(day,-13,@StartDate)] from table1