string query = string.Format("select a.ono,a.tno,a.tname,a.tdate,a.amount,b.name,b.age,b.sex from cscorder a,cscorder_item b where a.ono={0}",textBox6.Text);
将查询字符串作为您的查询。
@Damien_The_Unbeliever在评论中解释了错误消息的原因。 仅获得一个值的结果 ono (订单号我假设),你需要加入两个表 ono 值。 关于SQL中的连接 试试这个查询:
ono
Dim query as New StringBuilder() With query .AppendLine("SELECT ord.ono AS OrderOno") .AppendLine(", ord.tno") .AppendLine(", ord.tname") .AppendLine(", ord.tdate") .AppendLine(", ord.amount") .AppendLine(", itm.name") .AppendLine(", itm.age") .AppendLine(", itm.sex") .AppendLine("FROM cscorder ord") .AppendLine("LEFT JOIN cscorder_item itm ON itm.ono = ord.ono") .Append("WHERE ord.ono = ") .AppendLine(textBox6.Text) End With
但要认真考虑使用 SqlParameter 在你的查询中。它有很多帮助,不仅仅是sql注入。使用参数的一些示例: 来自MSDN 来自Stackoverflow
SqlParameter