avatar
i*p
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!
avatar
c*e
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!

avatar
i*p
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:

avatar
c*e
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

avatar
i*p
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
:
: "]

avatar
a*x
6
tostring

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

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

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

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

avatar
c*e
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.

avatar
i*p
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"]
avatar
k*e
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.

avatar
E*A
12
int id =(int)(dataReader.IsDBNull() ? 0 : dataReader.GetInt32(i));
//i 代表 categoryID 在SQL查询语句中的顺序
eventsXMLDoc.WriteAttributeString("id", id.ToString());
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。