Hello,
I am able to get the result set when I am giving a hardcoded value
( Ex: "WHERE LIKE 'B%' ") in a command text, but when I am trying to
give a parameter to that and passing a value, I am not able to get the
result set.
Ex: cmdObj.Text= "SELECT Phone FROM Person.Contact WHERE LastName
LIKE '@filter%' ";
SqlParameter param = new SqlParameter(") ;
cmdObj.Paramete rs.Add(param);
cmdObj.Paramete rs["@filer"].value= 'B';
can anyone please help me regarding this.
Thanks,
James 3 5539
It is just "...WHERE LastName LIKE @filter..." (no single quotes)
There is also a typo in the parameter name - you had "@filer", not
"@filter"
I would tend to do the + "%" in the C#, but you can do this in the
TSQL if you like:
"...WHERE LastName LIKE @filter + '%'..."
Marc
"James" <bo************ *@gmail.comwrot e in message
news:86******** *************** ***********@f63 g2000hsf.google groups.com...
I am able to get the result set when I am giving a hardcoded value
( Ex: "WHERE LIKE 'B%' ") in a command text, but when I am trying to
give a parameter to that and passing a value, I am not able to get the
result set.
Ex: cmdObj.Text= "SELECT Phone FROM Person.Contact WHERE LastName
LIKE '@filter%' ";
SqlParameter param = new SqlParameter(") ;
cmdObj.Paramete rs.Add(param);
cmdObj.Paramete rs["@filer"].value= 'B';
You need to add the "%" in the Value of the parameter, not in the query. And
the name of the parameter in the query string should not be surrounded by
quotes.
cmdObj.Text= "SELECT Phone FROM Person.Contact WHERE LastName
LIKE @filter";
SqlParameter param = new SqlParameter("@ filter", SqlDbType.Varch ar,
50);
cmdObj.Paramete rs.Add(param);
param.Value= '"B%";
On Oct 15, 12:09*pm, Marc Gravell <marc.grav...@g mail.comwrote:
It is just "...WHERE LastName LIKE @filter..." (no single quotes)
There is also a typo in the parameter name - you had "@filer", not
"@filter"
I would tend to do the + "%" in the C#, but you can do this in the
TSQL if you like:
"...WHERE LastName LIKE @filter + '%'..."
Marc
Thanks
James This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dcarson |
last post by:
I've read about this error in several other discussions, but still
can't seem to pinpoint the problem with my code. Everything seemed to
be working fine for some time, but it now tends to bomb out on me for
some reason. The Summary field is pulled from a Rich Text Editor that
allows HTML formatting and appears to be the culprit, but I just can't
seem to figure out why. Any guidance is greatly appreciated.
I'm connecting to an Access...
|
by: Megan |
last post by:
Hi-
I'm creating a database of music bands with their cds and songs.
I'm trying to program an SQL statement so that I can enter a string of
text in a textbox, press the 'Enter' key, and have it return the
associated records to a listbox. Once the listbox has the records, I
want to select a record, which will open a form associated with the
selected record in the listbox.
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header, example, and DLL:...
|
by: Dacuna |
last post by:
Is it possible to use a recursive function to loop through a recordset faster?
I have a table that I need to edit its contents after doing some calculation. The table has one field has an RawData field and a CalcData field. I open the recordset, exctract the RawData and after doing some calculations update the CalcData with the calculated data. In code I have something as follows.
dim rs as new ADODB.Recordset
dim cmdUpdate as new...
|
by: gurvar |
last post by:
hI,
i'M TRTYING TO PASS PARAMETER TO A SP.BUT GETTING "OUT OF RANGE ERROR ERROR
FOLLOWING IS THE CODE:
Dim conDG As SqlClient.SqlConnection
Dim cmdDG As SqlClient.SqlCommand
Dim drDG As SqlClient.SqlDataReader
Dim dtDueYear As String
Dim sqldataAdapter1 As SqlClient.SqlDataAdapter
dtDueYear = Trim(txtYear.Text)
' If (IsDate(dtDueYear) = True) Then
| |
by: John Salerno |
last post by:
I'm experimenting with this now and I'm a little confused about
transferring commands. This might be more of an FTP question than
strictly Python, but it's still related to how to use the ftplib methods.
Anyway, if what I want to do is send a command to change the file
permission settings of a file (or files), I assume I would use
transfercmd() and the command would be something like SITE CHMOD 755
name.py, for example.
What I'm...
|
by: vncntj |
last post by:
I have this syntax working perfectly, but I'm trying to apply a stored
procedure instead using
the CommandText (Sql Statement).
// Open connection to the database
string ConnectionString =
@"server=localhost;uid=;pwd=;trusted_connection=true;database=PMAEvents";
con = new SqlConnection(ConnectionString);
con.Open();
|
by: sheenaa |
last post by:
Hello Members,
I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005.
What i have used on forms :: ?
On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls.
On the click event of the command button the data gets stored into the database.
I have created the stored procedures for the insert,update,delete.
I have...
|
by: savage678 |
last post by:
Hi Everyone,
I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection.
I have some code which will allow me to do it but i dont know how to change the code. Could someone please help me. I have added the code for you to.
function MyQuery::OnClick(eventObj)
{
// Get the default SQL command for the form.
var...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |