由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - OleDbDataReader
相关主题
DataReader vs. DataSet关于泛型
HttpWebRequest小程序.Net 2.0 Window Form Property.Settings 问题
how they did elgooGWindows filesystem bug
how to use old DLL in VB .NET?[合集] asp 打开oracle数据库问题。
How to define a explict type cast funcvb.net problem
想在c#下调用另一个可执行文件问个STRING比较的问题
How to convert formated string to int请教 pass by value or reference 的问题
Curious for VBSCRIPT in ASP filehow to get the days difference between "3/1/2013" and "6/1/2013"
相关话题的讨论汇总
话题: categoryid话题: datareader话题: c#
进入DotNet版参与讨论
1 (共1页)
i**p
发帖数: 902
1
OleDbDataReader objDataReader;
...
objDataReader("categoryID")
They are fine in VB, but when I use these code to C#, the error message says:
CS0118: 'objDataReader' is a 'variable' but is used like a 'method'.
How to use OleDbDataReader rightly in C#?
Thanks!
c**e
发帖数: 2558
2
objDataReader["categoryID"]

says:

【在 i**p 的大作中提到】
: OleDbDataReader objDataReader;
: ...
: objDataReader("categoryID")
: They are fine in VB, but when I use these code to C#, the error message says:
: CS0118: 'objDataReader' is a 'variable' but is used like a 'method'.
: How to use OleDbDataReader rightly in C#?
: Thanks!

i**p
发帖数: 902
3
still has error on eventsXMLDoc.WriteAttributeString("id", dataReader["
categoryID"]);
CS1502: The best overloaded method match for 'System.Xml.XmlWriter.
WriteAttributeString(string, string)' has some invalid arguments
Here is the source code.
System.Data.OleDb.OleDbDataReader dataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
System.Xml.XmlTextWriter eventsXMLDoc = new
System.Xml.XmlTextWriter(Response.OutputStream, Encoding.UTF8);
// generate XM

【在 c**e 的大作中提到】
: objDataReader["categoryID"]
:
: says:

c**e
发帖数: 2558
4
dataReader["categoryID"] returns an object and not a string
you need to cast it to string

"]

【在 i**p 的大作中提到】
: still has error on eventsXMLDoc.WriteAttributeString("id", dataReader["
: categoryID"]);
: CS1502: The best overloaded method match for 'System.Xml.XmlWriter.
: WriteAttributeString(string, string)' has some invalid arguments
: Here is the source code.
: System.Data.OleDb.OleDbDataReader dataReader =
: dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
: System.Xml.XmlTextWriter eventsXMLDoc = new
: System.Xml.XmlTextWriter(Response.OutputStream, Encoding.UTF8);
: // generate XM

i**p
发帖数: 902
5
You are really cute! Please help to make me cute too. How to cast it to
string?

【在 c**e 的大作中提到】
: dataReader["categoryID"] returns an object and not a string
: you need to cast it to string
:
: "]

a***x
发帖数: 26368
6
tostring

【在 i**p 的大作中提到】
: You are really cute! Please help to make me cute too. How to cast it to
: string?

i**p
发帖数: 902
7
dataReader["categoryID"].ToString() ?
But when I use this in VB, it works without the cast.

【在 a***x 的大作中提到】
: tostring
c**e
发帖数: 2558
8
(string)dataReader["categoryID"]

【在 i**p 的大作中提到】
: You are really cute! Please help to make me cute too. How to cast it to
: string?

c**e
发帖数: 2558
9
turn on Option Strict on your VB code and see what happens

【在 i**p 的大作中提到】
: dataReader["categoryID"].ToString() ?
: But when I use this in VB, it works without the cast.

i**p
发帖数: 902
10
you are not cute this time.
[InvalidCastException: Unable to cast object of type 'System.Int32' to type
'System.String'.]
dataReader["categoryID"].ToString() works.

【在 c**e 的大作中提到】
: (string)dataReader["categoryID"]
k***e
发帖数: 7933
11
you need to know the type of data in your dataReader!

type

【在 i**p 的大作中提到】
: you are not cute this time.
: [InvalidCastException: Unable to cast object of type 'System.Int32' to type
: 'System.String'.]
: dataReader["categoryID"].ToString() works.

E******A
发帖数: 53
12
int id =(int)(dataReader.IsDBNull() ? 0 : dataReader.GetInt32(i));
//i 代表 categoryID 在SQL查询语句中的顺序
eventsXMLDoc.WriteAttributeString("id", id.ToString());
1 (共1页)
进入DotNet版参与讨论
相关主题
how to get the days difference between "3/1/2013" and "6/1/2013"How to define a explict type cast func
新人再问 sql/linq: No connection string name d 'db5Entities' could be found in the application config fi想在c#下调用另一个可执行文件
求助一个regular expressionHow to convert formated string to int
System.Data.SqlClient.SqlException: A network-related or instance -specific errorCurious for VBSCRIPT in ASP file
DataReader vs. DataSet关于泛型
HttpWebRequest小程序.Net 2.0 Window Form Property.Settings 问题
how they did elgooGWindows filesystem bug
how to use old DLL in VB .NET?[合集] asp 打开oracle数据库问题。
相关话题的讨论汇总
话题: categoryid话题: datareader话题: c#