请各位看看我的代码,能不能贴出个例子,到底该怎么写呢? 谢谢了,急等string cString = "server = (local); user id = sa; password =; database = pubs";
SqlConnection myConnection = new SqlConnection(cString);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.TableMappings.Add("Table", "Authors");
SqlCommand myCommand = new SqlCommand("SELECT * FROM authors",myConnection);
myCommand.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand;
ds = new DataSet();
myAdapter.Fill(ds);
this.myGrid.SetDataBinding(ds,"Authors");
SqlConnection myConnection = new SqlConnection(cString);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.TableMappings.Add("Table", "Authors");
SqlCommand myCommand = new SqlCommand("SELECT * FROM authors",myConnection);
myCommand.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand;
ds = new DataSet();
myAdapter.Fill(ds);
this.myGrid.SetDataBinding(ds,"Authors");
SqlConnection Connection = new SqlConnection(connectionString);
sqlCommand1 = new SqlCommand("SELECT * FROM 表名", Connection);
da = new SqlDataAdapter();
da.SelectCommand = sqlCommand1;
cb = new SqlCommandBuilder(da);
da.Fill(ds, "表名");
bindingSource1.DataSource = ds.Tables["表名"];
//设置bindingNavigator的数据源使其与DataGridView数据同步
dataGridView1.DataSource = bindingSource1;
SqlConnection Connection = new SqlConnection(connectionString);
cmd = connection.createcommand();
cmd.commandType=commandtype.storeprocedure;
cmd.commandText = "SELECT * FROM 表名";
sqldataadapter da = new sqldataadapter(cmd);
DataSet ds = new dataset();
da.Fill(ds, "表名");
dataGridView1.DataSource = ds.tables["表名"];
datagrid中也要相应设置
this.myGrid.DataBind();