读取数据库数据时 sdr.Fill(ds);附近有语法异常
读取数据库数据时 sdr.Fill(ds);附近有语法错误
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];
}
}
}
------解决方案--------------------
修改为
你里面有中文空格....
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];
}
}
}
------解决方案--------------------
com.CommandText = "select * from Disable";
修改为
com.CommandText = "select * from Disable";
你里面有中文空格....