SqlException was unhandled

On__nO 2011-04-13 11:19:57
private void button3_Click(object sender, EventArgs e)
{
string connectionString = "server=localhost;database=Train;integrated security=SSPI";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string sql = "with abc(a,b) as " +
"(select 车次,max([2]) " +
"from tmp " +
"group by 车次)" +
"select * " +
"from tmp,abc" +
"where tmp.车次=abc.a and tmp.发站='北京' and tmp.[2]=abc.b";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter dadpter = new SqlDataAdapter(cmd);
DataSet myDataSet = new DataSet();
int numberOfRows = dadpter.Fill(myDataSet,"one");
dataGridView1.DataSource = myDataSet.Tables["one"];
conn.Close();
}
每次点击button3 是就提示 "."附近有语法错
错误是在int numberOfRows = dadpter.Fill(myDataSet,"one");这句
...全文
49 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
On__nO 2011-04-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 blue2u 的回复:]
应该是这里有问题:
"where tmp.车次=abc.a and tmp.发站='北京' and tmp.[2]=abc.b"

你跟一下这句中的sql串是什么,
SqlCommand cmd = new SqlCommand(sql, conn);

要是没问题,再打开SQLSERVER的工具PROFILE跟踪一下发的SQL就知道哪里错了。
[/Quote]谢谢你了,发现错误在哪里了,原来是"from tmp,abc" 这一句,后边缺了个空格……
blue2u 2011-04-13
  • 打赏
  • 举报
回复
应该是这里有问题:
"where tmp.车次=abc.a and tmp.发站='北京' and tmp.[2]=abc.b"

你跟一下这句中的sql串是什么,
SqlCommand cmd = new SqlCommand(sql, conn);

要是没问题,再打开SQLSERVER的工具PROFILE跟踪一下发的SQL就知道哪里错了。

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧