如何阅读stringbuilder [英] how to read stringbuilder
本文介绍了如何阅读stringbuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里编写了一些代码来从sql服务器读取整数值:
Here I wrote some code to read an integer value from an sql server:
if (rdr.HasRows)
{
StringBuilder sb = new StringBuilder();
string a;
while (rdr.Read())
{
sb.Append(((int[field]).ToString());
sb.Append(\n);
a = sb.ToString().Trim();
c1.Items.Insert(count1, a);
sb.Length=0;
count1++;
}
}
现在我不明白如何读取数值和varchar.
在此处进行更改:
sb.Append(((int[field]).ToString());
Now I do not understand how to read a numeric value and varchar.
Changes somewhere here:
sb.Append(((int[field]).ToString());
推荐答案
从阅读器读取字段时,可以将其直接转换为存储为以下内容的数据格式:
When you read a field from the reader, you can cast it directly to the data format you stored it as:
int i = (int) rdr["intField"]; // Field: int
string s = (string) rdr["stringField"]; // Field: varchar
byte[] b = (byte[]) rdr["imageField"]; // Field: varbinary
除非您实际上需要这样做,否则不必将其转换为字符串并将其添加到StringBuilder!
You do not have to convert it to a string and add it to a StringBuilder, unless that is what you actually need to do!
如果我正确理解了您的问题,请使用rdr["fieldname"].ToString()
从DataReader读取值.
If I understand your question correctly, use rdr["fieldname"].ToString()
to read the values from the DataReader.
这篇关于如何阅读stringbuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文