Fill: SelectCommand.Connection 属性尚未初始化。
privateDataSetds=newDataSet();privateSqlConnectionconn=null;privateSqlDataAdapterda=n...
private DataSet ds = new DataSet();
private SqlConnection conn = null;
private SqlDataAdapter da = null;
// private SqlCommand cmd = null;
private const string DRIVER = "server=.;database=northwind;uid=sa;pwd=sa";
private const string sql_select = "select * from region";
/**/
/**
*
*
* * 此方法为将数据库northwind中的region表的数据查询出来并放入DataSet中
**/
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter(sql_select, conn);
da.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables["table"].DefaultView;
} 展开
private SqlConnection conn = null;
private SqlDataAdapter da = null;
// private SqlCommand cmd = null;
private const string DRIVER = "server=.;database=northwind;uid=sa;pwd=sa";
private const string sql_select = "select * from region";
/**/
/**
*
*
* * 此方法为将数据库northwind中的region表的数据查询出来并放入DataSet中
**/
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter(sql_select, conn);
da.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables["table"].DefaultView;
} 展开
3个回答
展开全部
实例化一个Connection conn = new Connection(ConnectionText) ;
SelectCommand.Connection = conn ;
conn.Open() ;
SelectCommand.ExecuteNonQuery() ;
conn.Close() ;
或者;
Connection conn = new Connection(ConnectionText) ;
DataAdapter da= new DataAdapter() ;
DataAdapter.SelectCommand = new Command() ;
DataAdapter.SelectCommand.Connection = conn ;
DataAdapter.SelectCommand.CommandText = selecttext ;
DataSet ds = new DataSet() ;
da.Fill(ds) ;
SelectCommand.Connection = conn ;
conn.Open() ;
SelectCommand.ExecuteNonQuery() ;
conn.Close() ;
或者;
Connection conn = new Connection(ConnectionText) ;
DataAdapter da= new DataAdapter() ;
DataAdapter.SelectCommand = new Command() ;
DataAdapter.SelectCommand.Connection = conn ;
DataAdapter.SelectCommand.CommandText = selecttext ;
DataSet ds = new DataSet() ;
da.Fill(ds) ;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void Form1_Load(object sender, EventArgs e)
{
//connection使用前须初始化
conn =new SqlConnection(DRIVER );
da = new SqlDataAdapter(sql_select, conn);
da.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables["table"].DefaultView;
}
还有问题追问或者HI 我~
{
//connection使用前须初始化
conn =new SqlConnection(DRIVER );
da = new SqlDataAdapter(sql_select, conn);
da.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables["table"].DefaultView;
}
还有问题追问或者HI 我~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
MySqlConnection my2;
MySqlData ms2;
MySqlData ms2;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询