473,379 Members | 1,245 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,379 software developers and data experts.

Passing Variables to sql command text-Newbe

Hello,
How do I pass variables to a command text.(C#)Because of the quotes,it
seems that the values are not passed.
Thanks,
Mike
Nov 17 '05 #1
1 3823
Hi Mike,
are you using a stored procedure or creating dynamic sql? If you are
using a stored procedure and using SQL Srver you can do something like:

SqlCommand command = new SqlCommand();
command.CommandText = "myStoredProcedureName";

//set the connection object
command.Connection = objConn;
command.CommandType = System.Data.CommandType.StoredProcedure;

//create parameter and add it to the command
SqlParameter param = new SqlParameter("@UserName",
System.Data.SqlDbType.VarChar, 30);
command.Parameters.Add(param);
If you are writing dynamic SQL then you could do something like:

string sqlCommand = "Select * from tblX WHERE UserName='" + userName + "'"
SqlCommand command = new SqlCommand(sqlCommand, objConn);

Hope that helps
Mark R Dawson

"Mike" wrote:
Hello,
How do I pass variables to a command text.(C#)Because of the quotes,it
seems that the values are not passed.
Thanks,
Mike

Nov 17 '05 #2

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

Similar topics

0
by: lawrence | last post by:
Those of you with backgrounds with the C language will laugh at my mistake, but those of you, like myself, who deal mostly with PHP should be warned about passing variables as references -...
7
by: Matthew Robinson | last post by:
i read a tutorial the other day on passing variables between php pages using a html form and setting the action to the php page to parse, can anybody see anything wrong with the code below? the...
2
by: Chieko Kuroda | last post by:
Hello all, I would like to learn the syntax for passing variables that I retreived from a database to a second asp page. Currently, I'm using: Response.Write "<tr><td>&nbsp;</td><td><Font size=...
1
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: -----------------------------------------------------------------------...
7
by: Khai | last post by:
First off, yes, I understand the crapload of tutorials out there, (well, rather, I understand there /are/ a crapload of tutorials out there), the problem is my comprehension. I'm trying to pass...
3
by: jsdeveloper | last post by:
Hi, I just started programming in javascript, and I'm having a problem passing variables between javascript and asp code in .asp page. Can you please help? I've given the sample code below. ...
1
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call...
6
by: coool | last post by:
Hi :) anyone knows how can I send variables from a php page to a form - i need to fill the form with these variables ? maybe using (the process of passing variables to other pages - through...
6
BezerkRogue
by: BezerkRogue | last post by:
This is the most fundamental action I am sure, but I can't seem to make it happen. I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have...
3
by: James | last post by:
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.