473,382 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to write a CommandText to include db values

Hi, i am baffled with this simple problem.

I want to try and pull out some info from a datatable,
using a sql query. i don't want to use a stored
procedure. How do i phrase my commandtext? i've messed
around with "+" symbols and extra apostrophes with no
success.

see my code:

private string test(SqlConnection conn)
{

string t = "";

SqlCommand cmd = new SqlCommand("SELECT Id FROM MyTable
WHERE Description = 'ugly'", conn);

cmd.ExecuteNonQuery();
return t;

}

thank you in advance,

Chief
Nov 17 '05 #1
2 1063
Hi Chief
I see you already added the command text in the initialization
SqlCommand cmd = new SqlCommand("SELECT Id FROM MyTable
WHERE Description = 'ugly'", conn);
So, what is the problem with that, would you elaborate more.
thx
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 17 '05 #2
Hi Chief,
from your sql, SELECT Id FROM MyTable WHERE Description = 'ugly' , will
return a value only if the 'ugly' exact mutch is exists in your DB, but
otherwise your phrase is correct. So i don't understant the prob, can you
clarify a bit more? you whant the ('ugly') part to add it to the string
dinamicaly?
"Chief" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
Hi, i am baffled with this simple problem.

I want to try and pull out some info from a datatable,
using a sql query. i don't want to use a stored
procedure. How do i phrase my commandtext? i've messed
around with "+" symbols and extra apostrophes with no
success.

see my code:

private string test(SqlConnection conn)
{

string t = "";

SqlCommand cmd = new SqlCommand("SELECT Id FROM MyTable
WHERE Description = 'ugly'", conn);

cmd.ExecuteNonQuery();
return t;

}

thank you in advance,

Chief

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hijwel | last post by:
<script language="JavaScript"> <!-- document.write('<form name="combo"><select name="example" size="1 onChange="Draw()">'); document.write('<option value=none>Maak je keuze');...
8
by: Jack | last post by:
Hi, Here is my problem: I am logging in to a page, where the page retrieves a record from a database. The text boxes are used in the display formto let the users update the fields, if they...
2
by: Tony Johansson | last post by:
Hello Experts!! I have two small classes called Intvektor and Matris shown at the bottom and a main. Class Intvektor will create a one dimension array of integer by allocate memory dynamically...
4
by: Tom Van Ginneken | last post by:
Hi, I need to write binary data to a serial port. I am using this function: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); I am able to write a alpha-numeric...
4
by: Sincere | last post by:
Hello All, Iam trying to ADD NEW RECORDS to my address book. but iam with an error, when i call the FILL method of the SqlDataAdaptor. Looking 4 assistance. The code is as follows TIA....
0
by: Berger | last post by:
Hello I generate and fill an excel sheet with oledb. My problem is, that I have to write more than 255 chars but I canīt find a datatype which I can use. I have tried datatype char,text,memo....
9
by: fniles | last post by:
When using VB6 and ADO, if I only do a Read, I will open a recordset with Forward Only cursor and Read Only lock, thus it will be faster than a non Read recordset. In VB.NET, when only need to do...
12
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me if I am using it right or not? Imports System.Data.sqlclient Imports System.Data Public Class Form1 Inherits...
1
by: xiao | last post by:
HI~ guys , I have a program here (Sorry it is very long about 240 lines.) It can read and write the header information successfully but it cannot write the array successfully. I guess there is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.