473,503 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use integer variable in OleDb query

How do I take a query like:

"string strOleDb = "Select * from ProjectTable WHERE ID = 4";

and pass in an integer variable for the ID, instead of the literal 4?

Thanks always,

-Tim Sprout
Jun 28 '07 #1
1 2089
Hi,
"Tim Sprout" <tm**@ptialaska.netwrote in message
news:Oj**************@TK2MSFTNGP05.phx.gbl...
How do I take a query like:

"string strOleDb = "Select * from ProjectTable WHERE ID = 4";

and pass in an integer variable for the ID, instead of the literal 4?
Replace with the correct classes:

using (SqlConnection con = new
SqlConnection(ConfigOptions.ConnectionString))
{
con.Open();
using (SqlCommand com = new SqlCommand())
{
com.CommandText = "InsertOffer";
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;

com.Parameters.Add("@offerID", SqlDbType.Int).Value =
offerId;

com.ExecuteNonQuery();
}
}
Jun 28 '07 #2

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

Similar topics

0
5263
by: silesius | last post by:
I've been using VS 2003 to develop a webapplication using C#. Today I exported the application to a remote webserver I begun experiencing problems. It's a simple application that retrieves some...
2
1589
by: VMI | last post by:
In Access, I can create a query like "select * from myTable where Name like '*Joe #*' " and it'll return records like ("Bob Joe 1", "Rick Joe 122", etc...). What's the equivalent to that in a...
4
3647
by: Robert Hanson | last post by:
Hi All, I am trying to add a record to a datatable that is connected to an Access database. I had no trouble with string and date fields, but for this record, I have two Long Integer field...
4
1619
by: Murph | last post by:
Hi, I'm new to ASP.NET and have a problem which i'm hoping will be easy to answer... i have only used VB, HTML and Flash up until now! I am designing an ASP page which uses OleDb to retrieve...
0
2738
by: silesius | last post by:
I've been using VS.NET 2003 to develop a webapplication using C#. Today I exported the application to another webserver I begun experiencing problems. It's a simple application that retrieves...
2
3507
by: Oberon | last post by:
Why does this not work as it should? I expect index.aspx to show:. Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\ChatSimple\db\chatusers.mdb Instead, I get: ...
5
1819
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
2
1524
by: Tom.Lismont | last post by:
Hi there, I'm currently working on a small project to create an overtime hour app. I'm a little bit stuck on the part where I want to make the sum of all the overtime hours entered in my db....
10
11280
by: Tony K | last post by:
How would I assign the result of a SQL query to a variable. The result of the following statement will ALWAYS result in 1 row returned. SELECT ProductDescription, ProductID FROM ...
0
7205
marktang
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,...
0
7093
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...
0
7287
Oralloy
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,...
0
7467
tracyyun
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...
0
4685
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...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
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 ...
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.