gpt4 book ai didi

asp.net - ODBC 全选命令

转载 作者:行者123 更新时间:2023-11-29 07:07:26 25 4
gpt4 key购买 nike

以下代码在限制为 0,1 时工作正常,当我将它们限制为 0,30 时我无法检索记录我确信我的数据库有足够数量的记录。但我怀疑 dr[3].ToString(); 之后的语法如何检索所有这些。

string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=malla_softmail2;" + "UID=xxx;" + "PASSWORD=xxx;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
OdbcCommand cmd = new OdbcCommand("Select * from awm_test where user=? limit= 0, 1", MyConnection);
cmd.Parameters.Add("@email", OdbcType.VarChar, 255).Value = "hello";
OdbcDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == false)
{
// throw new Exception();
}
if (dr.Read())
{
string a = dr[0].ToString();
string b = dr[1].ToString();
string c = dr[2].ToString();
//string d = dr[3].ToString();
//string f = dr[4].ToString();
//string g = dr[5].ToString();

Response.Write(a);
Response.Write(b);
Response.Write(c);
//Response.Write(d);
//Response.Write(f);
//Response.Write(g);

最佳答案

您只处理查询返回的第一条记录。尝试:

while (dr.Read()) {
string firstField = dr[0].ToString();
string secondField = dr[1].ToString();
string thirdField = dr[2].ToString();

// ...
}

关于asp.net - ODBC 全选命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6477428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com