C# 中SqlDataReader怎么获取列名
如题C#中SqlDataReader怎么获取列名SqlDataReadersdr=newSqlDataReader();sdr.Read();strings=sdr[0]...
如题
C# 中SqlDataReader怎么获取列名
SqlDataReader sdr = new SqlDataReader();
sdr.Read();
string s = sdr[0].列名
具体怎么弄 说下? 展开
C# 中SqlDataReader怎么获取列名
SqlDataReader sdr = new SqlDataReader();
sdr.Read();
string s = sdr[0].列名
具体怎么弄 说下? 展开
4个回答
展开全部
SqlConnection thisConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
// Open connection
thisConnection.Open();
// Create command for this connection
SqlCommand thisCommand = thisConnection.CreateCommand();
// Specify SQL query for this command
thisCommand.CommandText = sCommandText;
// Execute DataReader for specified command
SqlDataReader thisReader = thisCommand.ExecuteReader();
// While there are rows to read
//
//
View_LogDetailEntity = new List<CView_LogDetail>();//初始化集合
string sColumnName = string.Empty;
while (thisReader.Read())
{
CView_LogDetail myCView_LogDetail = new CView_LogDetail();
for (int i = 0; i < thisReader.FieldCount; i++)
{
sColumnName = thisReader.GetName(i).Trim();
}
}
展开全部
SqlConnection thisConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
// Open connection
thisConnection.Open();
// Create command for this connection
SqlCommand thisCommand = thisConnection.CreateCommand();
// Specify SQL query for this command
thisCommand.CommandText = sCommandText;
// Execute DataReader for specified command
SqlDataReader thisReader = thisCommand.ExecuteReader();
// While there are rows to read
//
//
View_LogDetailEntity = new List
();//初始化集合
string sColumnName = string.Empty;
while (thisReader.Read())
{
CView_LogDetail myCView_LogDetail = new CView_LogDetail();
for (int i = 0; i < thisReader.FieldCount; i++)
{
sColumnName = thisReader.GetName(i).Trim();
}
}
// Open connection
thisConnection.Open();
// Create command for this connection
SqlCommand thisCommand = thisConnection.CreateCommand();
// Specify SQL query for this command
thisCommand.CommandText = sCommandText;
// Execute DataReader for specified command
SqlDataReader thisReader = thisCommand.ExecuteReader();
// While there are rows to read
//
//
View_LogDetailEntity = new List
();//初始化集合
string sColumnName = string.Empty;
while (thisReader.Read())
{
CView_LogDetail myCView_LogDetail = new CView_LogDetail();
for (int i = 0; i < thisReader.FieldCount; i++)
{
sColumnName = thisReader.GetName(i).Trim();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sdr["id"]是数据库表中的id
sdr["id"]返回的是object类型,
用.tostring()返回string
sdr["id"]返回的是object类型,
用.tostring()返回string
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用datareader对象就可以了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询