Solution To Passing Parameters With Sql Text String.
Dec 26, 2003
I thought I would post this solution. I searched a long time and didnt see anything about how to solve my problem. After avoiding this and simply building strings I decided to dig in my heels and try and figure this out. Well, maybe I am just slow. :) Anyhow, here is some code that should help a lot of folks with this question...
Function GetProductCategories(ByVal departmentID) As DataSet
'set the connection string (comes from a property in this case)
Dim connection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringWeb"))
'set the sql text string notice the @DepartmentID is my parameter. protected from sql injections
Dim strSQL As String = "SELECT * FROM ProductCategory WHERE DepartmentID = @DepartmentID"
'set new command object to strsql and the connection. required
Dim command As New SqlCommand(strSQL, connection)
'set parameters to pass to through with the strsql. required for parameters. you can take this a set further. See commented fields below.
I am getting an invalid cast specification when I call dtexec and try to /SET a user variable within the package that is defined as a string data type. Is there any solution to this? I have tried passing the GUID with {} w/o {} w/ '' w/ "" etc.. many variations... and still get an invalid cast specification. Is there a data type that I need to set the User variable to besides String? The User Variable is used to Select records from a SQL data source where the GUID is stored. I do not have an option of GUID data type for a User Variable.
Where horseid id my parameter which is needed by report to generate the required data.
This query paramter value is picked from the text box on my jsp page.
But my problem is when i go to this url it says the message
"The 'HorseID' parameter is missing a value ".
In my report i have disabled the prompt user option , enable the Hide paramter option and has given no default value for this parameter.
I have done a lot of search on this topic. Everybody says that we can pass the values from the url like i am using. But still its not working. This forum is my last hope. Any body has any idea please give me some idea.
Hello, I have a number of multi-select parameters which I would like to send to a stored procedure within the dataset for use in the stored procedure's IN() statement which in turn is used to filter on or out particular rowsets.
I considered using a hidden string parameter set = " ' " + join(parameter.value, ',') + " ' " so that the hidden parameter would then contain a comma delimiated string of the values selected, which would then be sent on to the stored proc and used in the WHERE clause of one of the queries internal to the stored proc. But before I start dedicating time to do this I wanted to inquire if anyone here with far more expertise could think of a faster or less system heavy method of creating a single string of comma delimited parameter selections?
hi i am working with Asp.net2.0,Sqlserver2000. i uploaded my developed application to the webserver. all webpages are opening..bt when i try to interact with database it is raising error as following..
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
i set Enamble to namedPipes,Tcp/IP i set Remote connection to enable
my web.config looks like this.. <?xml version="1.0"?> <configuration> <appSettings> <add key="cn" value="User ID=redot;Password=redot;Data Source=216.185.43.148:1423;Initial Catalog=redot" /> <!--<remove key="LocalSqlServer"/> ;ProviderName=System.Data.SqlClient-->
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=216.185.43.148:1423;User ID=redot;Password=redot;Trusted_Connection=True" cookieless="false" timeout="60" /> <compilation debug="true" /> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. -->
i have a report with contains preview of percentage columns example of percentage of student marks in perticular subject like 95%. and if suppose any student not attend any test i have to dispaly like not attended statement.
so i have display two fields like 95% and not attended statement in same column, i given Cstr(Fields!Data.Value), it gives two fields with contains not attended statement of perticular query and it dispalys 0.95 % . but i need 95% and not attended statement for perticular query in same column.
is there any solution for dispalying string and percentage values in single column for given perticular query and those two values are disply same result compare with preview at the time of export to excel sheet
Hi, how to pass paremeters in sqldataadapter? here iam checking authentication using sqlcommand and datareader like that if iam checking authentication using dataset and sqldatareader how to use parameters?
SqlConnection cn = new SqlConnection("user id=sa;password=abc;database=xyz;data source=server"); cn.Open(); // string str = "select username from security where username='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'"; string str = "select username from security where username=@username and password=@password"; SqlCommand cmd = new SqlCommand(str, cn); cmd.Parameters.AddWithValue("@username", TextBox1.Text); cmd.Parameters.AddWithValue("@password", TextBox2.Text); SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows) { Session["username"] = TextBox1.Text; FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
} else { Label1.Visible = true; Label1.Text = "Invalid Username/Password"; } ------------------------------------------------------------------------------------- like that if iam checking authentication using dataset and sqldatareader how to use parameters?SqlConnection cn = new SqlConnection("user id=sa;password=abc;database=xyz; data source=server"); cn.Open();ds = new DataSet(); string str = "select username from security where username=@username, password=@password";da = new SqlDataAdapter(str, cn); //how to pass parameters for that da.Fill(ds, "security"); Response.Redirect("dafault2.aspx");
Still need help passing a criteria parameter query from a SQL Function (i.e. @StartDate) to a report header in Access Data Project where header = 'Transactions As Of [StartDate].
If anyone knows anywhere I can get help on this, I would really appreciate it. Thanks.
A little new to ASP.NET pages, and I'm trying to pass some parameters to a SQL 2000 Server using a TableAdapter, code is as follows: ------ TestTableAdapters.test_ModemsTableAdapter modemsAdapter = new TestTableAdapters.test_ModemsTableAdapter(); // Add a new modem modemsAdapter.InsertModem(frmRDate, frmModem_ID, frmProvisioning, strDecESN ); -------- And the error I get when loading the ASP.NET page is as follows: Compiler Error Message: CS1502: The best overloaded method match for 'TestTableAdapters.test_ModemsTableAdapter.InsertModem(System.DateTime?, string, string, string)' has some invalid arguments --------------- Now I realized the four strings that I am trying to pass to the server refer to ID's on Textboxes on the web page. Not sure if that might be the problem for databinding... ? Or is it my statement for the adapter? -Ed
The SQL for a dataset in ASP.NET 2.0 is as follows.... SELECT DISTINCT StudentData.StudentDataKeyFROM Student2Roster INNER JOIN StudentData ON Student2Roster.StudentDataRecID = StudentData.StudentDataRecIDWHERE (Student2Roster.ClassRosterRecID IN (@ClassRosterRecIDs) ClassRosterRecIDs are giuds At design time i use 'b2cf594d-908b-4c0c-a67f-6364899a4d42', '2e0b3472-d3f0-4a54-94af-bfc0a99525d9' as the parameter and it works in the designer but not at runtime. At runtime I get the error Conversion failed when converting from a character string to uniqueidentifier. If I leave the quotes off and only use 1 value like b2cf594d-908b-4c0c-a67f-6364899a4d42 it works.How can I use multiple guids as an IN parameter like 'b2cf594d-908b-4c0c-a67f-6364899a4d42', '2e0b3472-d3f0-4a54-94af-bfc0a99525d9'? Thanks
Hi I'm trying to add 2 date parameters to the where caluse but not sure how to structure it: Can anybody help? Public Function GetCategoryPerformance(ByVal PriorityType As String) As DataSet '******************************************************* 'This web service will return a specific row for a table '*******************************************************Dim cn As New SqlConnection("data source=CADTRAINING;persist security info=True;initial catalog=pathwaysreporting;user id=cad;password=cad;") Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * from sp_category_performance where where priority = '" & PriorityType & "'", cn)Dim ds As DataSet = New DataSet Try da.Fill(ds, "CategoryPerformance")Catch ex As Exception Throw New Exception(ex.Message) End TryReturn ds End Function End Class
I am executing a DTS package from an asp page using the following code. I would like to also pass DTS Global variables along. i assume this is possible but can't seem to find an example.
Set oPkg = Server.CreateObject("DTS.Package") oPkg.LoadFromSQLServer "HOFDBMCRM4","TraubGar","ripley",DTSSQLStgFlag_Default,"","","","DSC_CalculateBOS" oPkg.Execute()
I would like to pass parameters from isql command line to an input query file. I am working on SQL Server 7.0. How can I accomplish this?
My eg. is like this:
> isql.exe (all the server options etc.,) /iInputfile /oOutput file I need the output depend on the query given in the input file with the query depending on the parameter I supply on the command line.Thanks for your help in advance.
Can I pass a parameter to a view? Can something like this even be done?
CREATE view co_interlinks1 AS SELECT [TDirectorships].[IDDir], [TDirectors].[DirLName] + ', ' + [TDirectors].[DirFName] AS DirectorName, [TDirectorships].[Ticker], [TCompanies].[CompanyName] FROM TDirectorships INNER JOIN TCompanies ON [TCompanies].[Ticker]=[TDirectorships].[Ticker] INNER JOIN TDirectors ON [TDirectorships].[IDDir]=[TDirectors].[IDDir] WHERE [TDirectorships].[IDDir] in (SELECT [TDirectorships].[IDDir] FROM TDirectorships WHERE Ticker=@Ticker)--This line requires a variable value corresponding to Ticker for the chosen company and [TDirectorships].[Ticker] <> =@Ticker --This line requires a variable value corresponding to Ticker for the chosen company
Hi I created a report based on category,time and stores as report parameters.The datasets are created by using mdx queries and the provider I selected is olap services.I would like to add a bar chart in the layout and the resultant chart should be based on the selected parameters.I am not able to get this.First of all is it possible? If so, what should I do in the chart properties?
I have a requirement to load tables in the database from files on a shared server (lets say 50 tables from 50 files). I do not want to hardocde the file path anywhere in the package since this would mean changing 50 packages everytime the path changes (say when moving to to a diff server).
In SQL Server 2000, I used a .ini file to pass the path and used a Dynamic properties task to set run time variables. That way, evertime the path changes, I only had to change 1 ini file and all packages picked up the new path from it. How do I do this in SQL Server 2005 ?
Appreciate any assistance / suggestion in this regard.
I have a requirement to load tables in the database from files on a shared server (lets say 50 tables from 50 files). I do not want to hardocde the file path anywhere in the package since this would mean changing 50 packages everytime the path changes (say when moving to to a diff server).
In SQL Server 2000, I used a .ini file to pass the path and used a Dynamic properties task to set run time variables. That way, evertime the path changes, I only had to change 1 ini file and all packages picked up the new path from it. How do I do this in SQL Server 2005 ?
Appreciate any assistance / suggestion in this regard.
I have a report (Say Report 1)which is asking for a multivalue parameter Period. The user selects three period from the dropdown list available for the Parameter. Lets say that the user select 0407,0507,0607. Now is this report 1 there is a particular field which is linked to another sub report. So if the top level Report 1 supplies the revenue for 3 regions say for the periods selected then clicking on any of the regions would open a second detailed report, say Report 2 for the three periods as selected.
Till this everything is fine.
Now the problem is that in this detailed Report 2 there would be a particular text box as "Click here to naviagate back to parent report". So that when the user clicks on this cell he is taken back to the parent report, Report 1 which was originally generated for the 3 periods.
Can anyone please advise as to how the Multivalue Parameter which was passed from Report 1 to Report 2 can again be looped back to Report 1 from Report 2.
I have an OLE DB Source that talks to an Oracle Db and returns back some data. I need to be able to pass some parameters to my query from the SSIS variables.
How can accomplish this ? Do I need to create a stored proc in my Oracle DB..is that the only way I can pass parameters ? Is so how ?
Hi, I've read some threads in regards to passing report parameters through the 'URL' but I am struggling to fully understand. To keep things simple I have 1 report parameter, named par_pub which brings back either ww06 or ww07. What I require is to click on a hyperlink and it directs me to my report and then populates the par_pub paramerter with ww07.
The part in bold is the location + name of the report and the later is where I am trying to pass the parameter. Can anyone please help as this is not working.
I have a problem getting the URL string right to pass parameters from one report to another
This is the URL string I have set in the Navigation property of my text box: "http://SQL/Reportserver$SQL2005/Pages/Report.aspx?%2fEarlyWarning2%2fratio+reports+-+test%2freport_upper_lower_benchmark_ratio1&rs:Command=Render&rcarameters=false &company="&Parameters!company.Value.ToString()&Parameters!year.Value.ToString()&Fields!ratioName.Value.ToString()
The first thing is that when I just want to view the report say, with parameters hidden, I get this URL http://reportserver/?%2fEarlyWarning2%2fratio+reports+-+test%2freport_upper_lower_benchmark_ratio1&rs%3aCommand=Render&rc%3aParameters=false
with the message "Internet Explorer cannot display the webpage"
Why does the first part of the URL change?
If I run it with just one parameter, company, I get the same error message with this URL : http://reportserver/?%2fcompany.Value.ToString()&rs%3aCommand=Render&rc%3aParameters=false&company=%22
It looks like no value for the company parameter being passed
Hi, I have created a report in VS 2003 using command type as Text for a stored procedure. The stored procedure itself takes in 2 parameters. I have passed one of them in the exec statement but the other parameter is the one which I want to pass to the stored procedure through report. So, in short, I have got this statement in dataset
EXEC SP1 1
Which means only 1 of the arguments is being passed to the stored procedure and not the second one. I would appreciate if some one can guide me on how to pass a report parameter to the stored procedure which using command type text
Hai I am havng a DTS Package name MFT_Disb... I am invoking this package from my VB.NET(2003) Application.. What i want to do is .... 1 ) i want to pass a variable named Sl_No from my Application to the DTSPackage .. How can i pass the parameters to the package ? 2 ) Also i ve a text file named Disb.txt... i want to rename this text file to the value contained in the variable Sl_No... For renaming the text file i want to write ActiveX Script in the same DTSPackage ... How to write the ActiveX Script ? How can i rename the text file ? Anybody knows plz do help me ... I am new to SQL Server and DTSPackage Any help appreciated Thanx in advance
In the dataflow of my package, I must check from one table whether a row exists, and if that row exists, I should get some other row from another table, and update that..
I think to check whether a row exists, i should use "Look Up"
But cant we pass parameters to LookUP?
I am trying to use this SQL:
SELECT count(*) FROM ServicePackets where ID = ? and CHANGEDATE > ? and status = 1
I should get if that row exists or not only... (true or false)
Hello, I have a SQL task wich executes the following statement on a OLEDB connection (SQL 2005 DB):
TRUNCATE TABLE DimTime GO
DECLARE @CurrentDate AS Datetime DECLARE @EndDate AS Datetime
SET @CurrentDate = '10-20-2003'; SET @EndDate = '10-20-2005';
while(@CurrentDate < @EndDate) begin INSERT INTO DimTime SELECT DATEPART(month, @CurrentDate) AS MonthNumberOfYear ,DATEPART(quarter, @CurrentDate) AS CalendarQuarter ,DATEPART(year, @CurrentDate) AS CalendarYear ,dbo.GetSemester(DATEPART(month, @CurrentDate)) as CalendarSemester ,DATEPART(quarter, @CurrentDate) AS FiscalQuarter ,DATEPART(year, @CurrentDate) AS FiscalYear ,dbo.GetSemester(DATEPART(month, @CurrentDate)) AS FiscalSelester
set @CurrentDate = dateadd(month, 1, @CurrentDate) end GO
Now I want to parametrize the statement creating an external variable:
1. I created a datetime package variable (DimTimeStartDate)
2. Add update the above SQL statement to
SET @CurrentDate = ?;
3. I mapped the package variable to a new parameter (name 0)
Executing I get the following error:
[Execute SQL Task] Error: Executing the query " DECLARE @CurrentDate AS Datetime DECLARE @EndDate AS Datetime SET @CurrentDate = ?; SET @EndDate = '10-20-2005'; while(@CurrentDate < @EndDate) begin INSERT INTO DimTime SELECT DATEPART(month, @CurrentDate) AS MonthNumberOfYear ,DATEPART(quarter, @CurrentDate) AS CalendarQuarter ,DATEPART(year, @CurrentDate) AS CalendarYear ,dbo.GetSemester(DATEPART(month, @CurrentDate)) as CalendarSemester ,DATEPART(quarter, @CurrentDate) AS FiscalQuarter ,DATEPART(year, @CurrentDate) AS FiscalYear ,dbo.GetSemester(DATEPART(month, @CurrentDate)) AS FiscalSelester set @CurrentDate = dateadd(month, 1, @CurrentDate) end " failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.