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()); |