473,569 Members | 2,698 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 2091
Hi,
"Tim Sprout" <tm**@ptialaska .netwrote in message
news:Oj******** ******@TK2MSFTN GP05.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(C onfigOptions.Co nnectionString) )
{
con.Open();
using (SqlCommand com = new SqlCommand())
{
com.CommandText = "InsertOffe r";
com.CommandType = CommandType.Sto redProcedure;
com.Connection = con;

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

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

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

Similar topics

0
5272
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 information from an Access database. It worked fine when I ran on my computer. I use a parameterized query to retrieve some customer specific...
2
1594
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 query that's being run using OleDB? Thanks.
4
3653
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 types and I get the following error: "Data type mismatch in criteria expression." I am using OleDbType.Integer as the type which matched the Int32...
4
1631
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 data from an access database and show it on screen... however, i want the viewer to be able to select an item from a dropdown menu which relates to...
0
2748
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 some information from an Access database. It worked fine when I ran on my home computer. I use a datagrid witha a dataset and a parameterized query...
2
3511
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: Provider=Microsoft.Jet.OLEDB.4.0;Data
5
1822
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 CNAME = 'MICROSOFT'" This does not work: Dim var as string
2
1525
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. I'm working with an Access db. Users can enter the amount of overtime hours performed on a single day. Every day is 1 record. What I want to do now...
10
11287
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 Products WHERE (ProductIDNumber = ?) How do I assign the...say, ProductDescription to a variable called prodDesc? Thanks,
0
7612
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...
0
7924
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, 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. ...
1
7672
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...
0
7968
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 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...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
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...
1
2113
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
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.