473,750 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asign a parameter command2

I use the parameter command,

cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;

I receive the error,

Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to
'System.Data.Ol eDb.OleDbDataRe ader'

t_var is declared as an int. So what's the problem?
Nov 16 '05 #1
4 1882
Can you show us a bit more code?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Da***@web. com" <Da*********@di scussions.micro soft.com> wrote in message
news:F3******** *************** ***********@mic rosoft.com...
I use the parameter command,

cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;

I receive the error,

Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to
'System.Data.Ol eDb.OleDbDataRe ader'

t_var is declared as an int. So what's the problem?

Nov 16 '05 #2
Yes, here is all the code,

string conVar = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\\data \\data;Extended Properties=dBas e 5.0";
string conVarCommand= "Select var From mob_var";

OleDbConnection cn= new OleDbConnection ();
cn.ConnectionSt ring= conVar;
cn.Open();

OleDbCommand cmd = new OleDbCommand(co nVarCommand, cn);
OleDbDataReader dtrVar = cmd.ExecuteRead er();
string VarText;
if (dtrVar.Read()) {
VarText= dtrVar["var"].ToString();
}
int t_var;
t_var = Convert.ToInt32 (dtrVar["var"]);
t_var += 1;

conVarCommand= "Update mob_var Set var=@var_new";
cmd = new OleDbCommand(co nVarCommand, cn);
cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;
dtrVar = cmd.ExecuteNonQ uery();
Response.Write( "Var-"+t_var);
cn.Close();

"Miha Markic [MVP C#]" wrote:
Can you show us a bit more code?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Da***@web. com" <Da*********@di scussions.micro soft.com> wrote in message
news:F3******** *************** ***********@mic rosoft.com...
I use the parameter command,

cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;

I receive the error,

Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to
'System.Data.Ol eDb.OleDbDataRe ader'

t_var is declared as an int. So what's the problem?


Nov 16 '05 #3
Hi David,

First thing is that you really have to Close reader before using another
reader with the same connection.
The other thing is, that you should replace parameter name with question
mark:
conVarCommand= "Update mob_var Set var=@var_new";
change to
conVarCommand= "Update mob_var Set var=?";

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Da***@web. com" <Da*********@di scussions.micro soft.com> wrote in message
news:98******** *************** ***********@mic rosoft.com...
Yes, here is all the code,

string conVar = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\\data \\data;Extended Properties=dBas e 5.0";
string conVarCommand= "Select var From mob_var";

OleDbConnection cn= new OleDbConnection ();
cn.ConnectionSt ring= conVar;
cn.Open();

OleDbCommand cmd = new OleDbCommand(co nVarCommand, cn);
OleDbDataReader dtrVar = cmd.ExecuteRead er();
string VarText;
if (dtrVar.Read()) {
VarText= dtrVar["var"].ToString();
}
int t_var;
t_var = Convert.ToInt32 (dtrVar["var"]);
t_var += 1;

conVarCommand= "Update mob_var Set var=@var_new";
cmd = new OleDbCommand(co nVarCommand, cn);
cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;
dtrVar = cmd.ExecuteNonQ uery();
Response.Write( "Var-"+t_var);
cn.Close();

"Miha Markic [MVP C#]" wrote:
Can you show us a bit more code?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Da***@web. com" <Da*********@di scussions.micro soft.com> wrote in message
news:F3******** *************** ***********@mic rosoft.com...
>I use the parameter command,
>
> cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;
>
> I receive the error,
>
> Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to
> 'System.Data.Ol eDb.OleDbDataRe ader'
>
> t_var is declared as an int. So what's the problem?


Nov 16 '05 #4
After making the suggested changes I received the same error. Then I tried
totally closing the connection and then reopening it, and I received the same
error.

"Miha Markic [MVP C#]" wrote:
Hi David,

First thing is that you really have to Close reader before using another
reader with the same connection.
The other thing is, that you should replace parameter name with question
mark:
conVarCommand= "Update mob_var Set var=@var_new";
change to
conVarCommand= "Update mob_var Set var=?";

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Da***@web. com" <Da*********@di scussions.micro soft.com> wrote in message
news:98******** *************** ***********@mic rosoft.com...
Yes, here is all the code,

string conVar = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\\data \\data;Extended Properties=dBas e 5.0";
string conVarCommand= "Select var From mob_var";

OleDbConnection cn= new OleDbConnection ();
cn.ConnectionSt ring= conVar;
cn.Open();

OleDbCommand cmd = new OleDbCommand(co nVarCommand, cn);
OleDbDataReader dtrVar = cmd.ExecuteRead er();
string VarText;
if (dtrVar.Read()) {
VarText= dtrVar["var"].ToString();
}
int t_var;
t_var = Convert.ToInt32 (dtrVar["var"]);
t_var += 1;

conVarCommand= "Update mob_var Set var=@var_new";
cmd = new OleDbCommand(co nVarCommand, cn);
cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;
dtrVar = cmd.ExecuteNonQ uery();
Response.Write( "Var-"+t_var);
cn.Close();

"Miha Markic [MVP C#]" wrote:
Can you show us a bit more code?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Da***@web. com" <Da*********@di scussions.micro soft.com> wrote in message
news:F3******** *************** ***********@mic rosoft.com...
>I use the parameter command,
>
> cmd.Parameters. Add("@var_new", OleDbType.Integ er).Value= t_var;
>
> I receive the error,
>
> Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to
> 'System.Data.Ol eDb.OleDbDataRe ader'
>
> t_var is declared as an int. So what's the problem?


Nov 16 '05 #5

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

Similar topics

3
16946
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
2
2758
by: John A Grandy | last post by:
Is there something special in XML about the name "Parameter" ... I am not able to XPATH query for nodes named "Parameter" <Root> <Category CategoryID="1"> <Elements> <Element ElementID="1"></Element> <Element ElementID="2"></Element> <Element ElementID="3"></Element> </Elements>
2
19346
by: PK | last post by:
Hi, I have an application that opens a Crystal report document and passes in a value to a parameter in the report (pointing to an Oracle DB). However, if I want to pass a "null" value to retrieve all records that have no data for the specified field that the parameter is a condition of (ie. SELECT * from <table> where <field> is null"), it returns nothing. I think CR is building the SQL statement like "SELECT * from <table> where <field>...
7
9567
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a subroutine Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created How do I pass such a parameter Thanks in advance Richar
4
2758
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx to a stored procedure on the details2.aspx page. I can successfully pass the values from the listbox control to a
16
3164
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the parameter will not be changed - so don't worry. 2. It tells the implementor and the maintainer of this function that the parameter should not be changed inside the function. And it is for this reason that some people advocate that it is a good idea to...
3
8017
by: Ken Cox [Microsoft MVP] | last post by:
I've been going around and around on this one. I can't believe that it is "by design" as Microsoft says. Here's the situation: In *declarative* syntax, I'm trying to create a default datetime value for a SqlDataSource parameter. (I know how to insert this parameter in code. I want to use declarative markup.) Here's the declarative markup with ???????? indicating where I'm stumped.
20
5243
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to write the parameter, I want to select a row from the listbox and after clicking in a button, the query to automatically take the current value of listbox as the needed parameter and then to load the query. (The Inputbox for "Enter Parameter" will...
5
5307
by: Trevisc | last post by:
Happy Thursday Everyone, I am trying to create a parameter that is one long varchar but that will be used in a SQL statement IN function: //string queryString = GetCurrentTitles(); //Below is for Test string queryString = "45322,32222,33344,55555"; dataset catalogDS = new dataset();
0
9001
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, 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...
0
8839
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,...
0
9584
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6811
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
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();...
0
4716
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3327
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
2
2809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2227
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.