读取数据库数据时 sdr.Fill(ds);附近有语法错误

坏蛋昆虫 2014-07-26 11:11:23
1. 数据库中的表示Disable。

2.using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace dataS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string str = "Data Source=PC028-PC\\SQLEXPRESS;Initial Catalog=model;Integrated Security=True";
SqlConnection conn = new SqlConnection(str);
conn.Open();

SqlCommand com = new SqlCommand();
com.Connection = conn;
com.CommandText = "select * from Disable";
com.CommandType = CommandType.Text;

SqlDataAdapter sdr = new SqlDataAdapter();
sdr.SelectCommand = com;

DataSet ds = new DataSet();
sdr.Fill(ds);
//conn.Close();
dataGridView1.DataSource = ds.Tables[0];
}
}
}
...全文
67 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
坏蛋昆虫 2014-07-26
  • 打赏
  • 举报
回复
引用 1 楼 diaodiaop 的回复:

com.CommandText = "select * from Disable";
修改为

com.CommandText = "select * from Disable";
你里面有中文空格....
嗦嘎,谢谢啦。难怪我检查这么久都没有检查出来。。 还是先改运行下Sql语句比较好
by_封爱 版主 2014-07-26
  • 打赏
  • 举报
回复

com.CommandText = "select * from Disable";
修改为

com.CommandText = "select * from Disable";
你里面有中文空格....

110,572

社区成员

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

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

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