C#绑定数据库哪里错了 不显示数据库
来源:百度知道 编辑:UC知道 时间:2024/07/03 12:36:21
{
SqlConnection myconn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
DataSet myds = new DataSet();
try
{
myconn.ConnectionString = "data source=(local);database=Northwind;Integrated Security=SSPI;";
myconn.Open();
cmd.CommandText = "select * from Customers";
cmd.Connection = myconn;
SqlDataAdapter myadapter = new SqlDataAdapte(cmd);
myadapter.Fill(myds);
this.dataGridView1.DataSource = myconn;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
this.dataGridView1.DataSource = myconn;
改成,this.dataGridView1.DataSource = myds; 基本上会有数据,但是没有对应好.
试试看用OleSqlConnection……后面全加上ole
这是我改的程序,你看看,我试着是可以了,我把你的连接语句注释了,你到时候把我的注释掉就行了,我在页面上拖了一个GridView(ID="GridView1)和一个Button(Button1),下面的是后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection();
//myconn.ConnectionString = "data source=(local);database=Northwind;Integrated Security=SSPI;";
myconn.ConnectionString = "Data Source=192.168.0.8;Initial Catalog=Northwind;User ID=sa;Password=123";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Customers";
cmd.Connection = myconn;
try
{
myconn.Open();
SqlDataAdapter myadapter = new SqlDataAdapter();
DataSet myds = new DataSet();
myada