SqlDataSource : Dynamic SQL : Apostrophe
Sep 20, 2007
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
View 3 Replies
ADVERTISEMENT
Nov 14, 2006
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.
View 2 Replies
View Related
May 14, 2007
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!
View 3 Replies
View Related
Mar 20, 2008
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?
View 2 Replies
View Related
Jan 16, 2006
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.
View 3 Replies
View Related
Jul 20, 2007
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 %>"
SelectCommand="usp_reports_shortages" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="lblDriver" Name="date1" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="lblTODate" Name="date2" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="DDlDriver" Name="driver" PropertyName="SelectedValue"
Type="Int32" />
<asp:SessionParameter Name="week" SessionField="s_week" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
View 1 Replies
View Related
Apr 25, 2008
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?
View 5 Replies
View Related
Mar 29, 2006
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>
View 3 Replies
View Related
Aug 9, 2005
how do i search a column and find all rows where there is a single ' in the column?
View 2 Replies
View Related
Jul 20, 2005
i'm using delphi 7 and have a query in which i'm trying to find namesthat have an apostrophe in them, i.e. "o'mally". my problem is thatwhen i write my select statement i can't get the quotes right. i getall types of errors no matter what i try. i get "missing right quote","invalid token" etc. i've tried using QuotedStr and nothing works.here is my current attempt in which i get an "invalid use of keyword.token: n'%'"sSQL := 'SELECT statenotified, notary_id, LastName, FirstName,' +' MiddleInitial, Indep, Book_number, Page_number,' +' CloseRec, TermBegins, TermEnds, DatePickedUp,FailedToQualify,' +' Notes, SOSLtrSent FROM notaries WHERE LastName LIKE '''+''+ edtLastName.Text+'+''%'' AND CloseRec = 1 order bylastname';
View 2 Replies
View Related
Dec 3, 2007
Hi Friends,
I have stored names with ' s (Apostrophes) and without 's in the database(sqlserver).Example:O'Relly
I tried to get the values with select statement like
Dim str As String = Request.QueryString("Title")
Dim query As String = "SELECT * FROM Test where title like '" + str + "'"
Problem is getting the all the values from database except O'Relly just getting O other word Relly no.....
What should do I and what code do I need ..?
I tried with the below code also
Dim x As Long
For x = 1 To Len(str)
If Mid$(str, x, 1) = "'" Then
str = str & "''"
Else
str = str & Mid(title1, x, 1)
End If
Next
Need help ,
Thanks.
View 10 Replies
View Related
Jan 8, 2008
I need help with a simple query. We have 86 entries with the City of O'Fallon in our db. How do I do this with the apostrophe in O'Fallon? Below is just to give an idea of what I want. Thanks.
SELECT *
FROM Organization
WHERE City=O'Fallon
View 2 Replies
View Related
Mar 7, 2005
I get this error when the user inputs a word with an apostrophe:
Incorrect syntax near 't'. Unclosed quotation mark before the character string '
Using c# this is the input command:
oCom=new SqlCommand(string.Format("INSERT INTO [database] ([name],[address], [issue],[comments],[timestamp]) VALUES({0},'{1}','{2}','{3}','{4}",val[0],val[1],val[2],txtComment.Text,tmStamp),oCon);
When users enter a comment with an aprostrophe it gives me an error, using a session array and convert it to a string[].
Any ideas?
Thanks
View 1 Replies
View Related
Apr 16, 2002
we need to cut the aprostrophe out of a name (ie...o'brien, o'leary) to create userid's... can this be done....thanks!
View 1 Replies
View Related
Apr 18, 2000
Hello
Can anyone tell me how to replace a single apostrophe in a record with a double apostrophe (in Query Analyzer, SQL7)? I've tried "select replace("d'","d'","d''")FROM RESORT" but it doesn't UPDATE the table.
Suggestions gratefully received!
Mark
View 1 Replies
View Related
Jun 14, 2004
Ok, I still have some uncertainty as to just exactly how this whole apostrophe thing works with databases. I understand that it is a reserved character and so when a sql query runs into one of these creatures it looks at it as something other than a normal character.
I am working primarily in vb/asp/sql server with a little bit of access. I am familiar with the instrinsic 'Replace' function and I use it but I still have occassional problems.
I would like any information I can get on just exactly why/how this thing works and how to work-around the apostrophe when writing to, reading from, and validating data from sql server/access/any databases.
Thanks!
View 1 Replies
View Related
May 7, 2007
I am having weird trouble with READING data from my Access database where the field has an apostrophe - but only when I display the field in a textbox.
For example, the field "Don't do this" becomes "Don" when my SQL query outputs the result:
campaignID = rscampaign("campaign")
response.write "<input type='hidden' name='campaignid1' value='" & campaignID & "'>"
If I output to regular HTML (e.g. in a <P> tag), the field displays correcly.
Has anyone ever encountered this problem? I can't figure out why the textbox would be creating this problem...
View 7 Replies
View Related
Jun 5, 2007
replace(lastname," ' '",'"x"') (spaces for clarity only)
Result:
Invalid column name ' ' '.
How do I get around the invalid column name?
Thanks in advance for your assistance!
View 10 Replies
View Related
Aug 17, 2007
Hey I have what I think is a simple question. How would i insert an apostrophe into a sql string without getting an error. Thanks in advance
View 5 Replies
View Related
Jan 23, 2008
Hi all,I am not sure this question will belong to a sql group or .net.but the problem I have is, my data entry forms crashes when some enter a apostrophe character in one of the field. that field is of type varchar in sql server 2000.for ex, Ryan O'neill will crash the application.
I have a drop down list of all my crew names in my form.what should I need to do to allow user to add apostrophe and not to have application crash?Please help it is very urgent.Thank You,
View 1 Replies
View Related
Feb 5, 2004
I have a brain teaser for you all.
The end result: I need one of the columns in my result set (col2) to have a preceeding apostrophe (i.e., '001234 ).
The problem: I am building my query as a string and then using the EXEC() function to execute it. For example:
SET @strSQL = 'SELECT col1, col2 FROM mytable'
EXEC(@strSQL)
Just to tame any answers that might not be directed to the specific question, the query Must be built as a string and then executed.
I have been unable to obtain the solution and I am wondering if it is even possible?
TIA
View 3 Replies
View Related
Mar 8, 2000
I would like to add an apostrophe in a string. eg. The boy's shoes.
Everytime I insert the record, the apostrophe gets drop. eg. The boys shoes.
Any suggestions??
Thanks, Vic
View 2 Replies
View Related
Sep 4, 2004
Hi there,
I have an access 2000 db and in one of my tables I need to store some text that sometimes contains an apostrophe.
My problem is, everytime my program tries to insert text containing an apostrophe, the program crashes...
The insert statments I am using look like this:
CurrentDb.Execute "INSERT INTO myTable (Text) VALUES ('" & stringContainingApostrophe & "')"
I've tried checking the text for apostrophes and replacing them with an ecape character + apostrophe ("'") but that doesn't work either...
It seems like I should be able to store text that contains an apostrophe... Am i missing something here?
Does anyone have any ideas?? (Thanks in advance)
View 1 Replies
View Related
Nov 10, 2006
Hi, i'm having problems executing the followingSET @SQLAH = 'SELECT sub_id WHERE 'SET @SQLAH = @SQLAH + 'VENUE_TYPE = Hotel'EXEC(@SQLAH)Its getting stuck at Hotel. I realise that it should include an apostrophe either side like so:..SET @SQLAH = @SQLAH + 'VENUE_TYPE = 'Hotel' '..But this escapes the string, how would i escape an apostrophe in a string?I thought maybe:SET @SQLAH = @SQLAH + 'VENUE_TYPE = 'Hotel' 'But no joy :confused: Thanks
View 4 Replies
View Related
Aug 6, 2013
I am having a problem trying to pull data that has apostrophe in them. How can I do this? I get this as an error
Msg 105, Level 15, State 1, Line 14
Unclosed quotation mark after the character string ''.
Select
Name
From Table
Where Name IN (CHILDREN'S ANES ASSOCS-CHOP,CHILDREN'S HEALTHCARE-CHOP,CHILDREN'S PSYCH ASSOC-CHOP,CHILDREN'S SURGICAL ASSOC-CHOP)
View 4 Replies
View Related
Nov 15, 2006
Getting an error when i execute the query.
select * from trio where ad_str1 like '%''
Server: Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark before the character string '%'
'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '%'
'.
View 1 Replies
View Related
Nov 16, 2007
How do you get the following to work properly?
WHERE Location = 'John's House'
The apostrophe between n and s has me stumped. Thanks.
View 6 Replies
View Related
Mar 19, 2008
Hai,
In my datedabase I have some customers with the next name: 't Woud.
The problem is the apostrophe in my query for my drill through.
This is my query:
SELECT DISTINCT c.alias AS Client, p.Alias AS Periode, u.alias as Product, v.alias as Verschil, CAST(s.indicatie AS decimal(6, 2)) AS Indicatie, CAST(s.realisatie AS decimal(6, 2)) AS Realisatie, CAST(s.real_indic AS decimal(6, 2)) AS [Realisatie -/- Indicatie], CAST(s.indicatie_fin AS decimal(6,0)) AS [Indicatie Fin], CAST(s.realisatie_fin AS decimal(6,0)) AS [Realisatie Fin], CAST(s.real_indic_fin AS decimal(6,0)) AS [Realisatie -/- Indicatie Fin]
FROM [BI_TZR].dbo.fact_clientsignaal s INNER JOIN
[BI_TZR].dbo.dim_verschil v ON s.verschil = v.verschil INNER JOIN
[BI_TZR].dbo.Dim_Periodewk p ON s.periode = p.Periode INNER JOIN
[BI_TZR].dbo.dim_client_uren c ON s.client_id = c.id INNER JOIN
[BI_TZR].dbo.dim_product u ON s.product = u.product
WHERE (LEFT(p.Alias, 1) = 'p') AND (c.alias like '%794735%') and s.kplts <> '1583'
ORDER BY s.product, s.periode
I try this:
SELECT DISTINCT replace ( c.alias, 'd', '') AS Client, this works, for the caracter D. But know I want it for the caracter apostrophe.
Can someone help me??
TNX
View 8 Replies
View Related
May 30, 2007
How can I insert ' (Apostrophe) into sql table field ?
Insert Into Table(Field) Values(?)
After executing sql statement above, I want to see ' (apostrope) in field.
Thanks
View 3 Replies
View Related
Aug 7, 2007
heyi'm having a problem with a stored procedure, to cut a long story short i need to replace apostrophe's in my text, like soSET @prOtherValue = REPLACE(@prOtherValue,''', '''')this doesn't work thowhats the work aroundcheers!!!!
View 6 Replies
View Related
Sep 30, 2002
Hello,
I'm using Visual Basic 6 to insert data into SQL Server 2000 via a stored procedure. Apostrophes are giving me problems. Using T-SQL it works fine.
Following is the code:
=======================
cn.ConnectionString = "Driver=" & cnDriver & ";Server=" & cnServer & ";Database=" & cnDatabase & ";UID=" & cnUID & ";PWD=" & cnPWD
cn.Open
'TURNING QUOTES OFF allows a literal string to be delimited by double quotes and to accept an apostrophe
'cn.Execute "SET QUOTED_IDENTIFIER OFF" (This works using T-SQL statements only)
'set the reference to the ADO Command object
Set cmd = New ADODB.Command
'Set the command object properties
Set cmd.ActiveConnection = cn
pDocClass = "Apostrophe's test"
'THIS STORED PROC. INSERTS DATA INTO THE 'INDEX_DTL' AND 'CSC_TRANS' TABLES
cmd.CommandText = "Insert_Email_Data ('" & pDocID & "', '" & pLoginID & "', '" & pCustNum & "', '" & pDocClass & _
"', '" & pJCIRepCode & "', '" & pInitiallyRoute & "','" & pDocRecDate & "', '" & _
pCustPONum & "', '" & pJCIOdrNum & "', '" & strDateTime & "', '" & strTime & "', '" & _
strEmailDate & "', '" & strEmailTime & "', '" & strBatchCreationID & "', '" & _
"X" & "', '" & strEventType & "')"
MsgBox cmd.CommandText
cmd.CommandType = adCmdStoredProc
cmd.Execute
=======================
The above works great as long as the pDocClass field does not contain an apostrophe. In the stored procedure, pDocClass is defined as @pDocClass char (40).
Following is the error I receive:
"Line 1: Incorrect syntax near '{'
Any help with handling an apostrophe in the CommandText above would be greatly appreciated!
Thanks,
aml
View 2 Replies
View Related
Mar 16, 1999
Dear fellows,
I want to insert the data in a field which contains apostrophe['] in it, but the insert command does not stores the test after apostrophe
e.g
Insert into test_tbl(id,name)
values (32,'This is a test of apostrophe's ...');
the above command does not store after first apostrophe.
Please suggest
-Faisal
View 2 Replies
View Related
Aug 12, 2004
I have a insert statement but one of the strings contains a apostrophe. If I leave the apostrophe in an error occurs becuase it thinks that it is the end of the string. What is the proper syntax for including apostrophes in a string?
Thanks.
View 8 Replies
View Related