gpt4 book ai didi

c# - C#中的选择语句

转载 作者:搜寻专家 更新时间:2023-10-30 21:43:14 25 4
gpt4 key购买 nike

我的代码哪里出了问题?

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=C:\\Users\\Simon\\Desktop\\test5\\test5\\test5\\save.mdb";

OleDbConnection conn = new OleDbConnection(constr);
string sql = "SELECT users.user_name,naziv,obroki_save.datum"
+ "FROM zivila JOIN obroki_save ON zivila.ID=obroki_save.ID_zivila"
+ "JOIN users ON obroki_save.ID_uporabnika=users.ID";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader;
reader = cmd.ExecuteReader();

while (reader.Read())
{
Console.Write(reader.GetString(0).ToString() + " ,");
Console.Write(reader.GetString(1).ToString() + " ,");
Console.WriteLine("");
}

reader.Close();
conn.Close();

最佳答案

如果您在调试器中运行它,您可以看到问题:

SELECT users.user_name, naziv,obroki_save.datumFROM zivila JOIN obroki_save ...
^^^^

您的 SQL 中缺少空格。应该是这样的:

string sql = "SELECT users.user_name,naziv,obroki_save.datum " // << here
+ "FROM zivila JOIN obroki_save ON zivila.ID=obroki_save.ID_zivila " // << here
+ "JOIN users ON obroki_save.ID_uporabnika=users.ID";

关于c# - C#中的选择语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2754714/

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