怎么通过sqldatareader来显示数据空中想查询的信息(显示在Datagridview上)
我想按期查询彩票con=newSqlConnection();con.ConnectionString="server=.;database=caipiao;uid=sa...
我想按期查询彩票
con = new SqlConnection();
con.ConnectionString = "server=.;database=caipiao;uid=sa;pwd=123";
string sql = "select * from t_LotInfo whereType=@ype and Term=@Term";
com = new SqlCommand(sql,con);
com.Parameters.Add("@Type",SqlDbType.VarChar).Value = comboBox1.Text;
com.Parameters.Add("@Term", SqlDbType.VarChar).Value = textBox1.Text;
SqlDataReader dr = com.ExecuteReader();
接下来该怎么写了? 展开
con = new SqlConnection();
con.ConnectionString = "server=.;database=caipiao;uid=sa;pwd=123";
string sql = "select * from t_LotInfo whereType=@ype and Term=@Term";
com = new SqlCommand(sql,con);
com.Parameters.Add("@Type",SqlDbType.VarChar).Value = comboBox1.Text;
com.Parameters.Add("@Term", SqlDbType.VarChar).Value = textBox1.Text;
SqlDataReader dr = com.ExecuteReader();
接下来该怎么写了? 展开
2个回答
展开全部
一楼的回答 不对~~~~
Using System.Data;
con = new SqlConnection();
con.ConnectionString = "server=.;database=caipiao;uid=sa;pwd=123";
string sql = "select * from t_LotInfo whereType=@ype and Term=@Term";
com = new SqlCommand(sql,con);
com.Parameters.Add("@Type",SqlDbType.VarChar).Value = comboBox1.Text;
com.Parameters.Add("@Term", SqlDbType.VarChar).Value = textBox1.Text;
SqlDataReader dr = com.ExecuteReader();
DataTable dt = new DataTable ();
dt.Load(dr);
this.datagridview.datasource=dt;
conn.Close();
Using System.Data;
con = new SqlConnection();
con.ConnectionString = "server=.;database=caipiao;uid=sa;pwd=123";
string sql = "select * from t_LotInfo whereType=@ype and Term=@Term";
com = new SqlCommand(sql,con);
com.Parameters.Add("@Type",SqlDbType.VarChar).Value = comboBox1.Text;
com.Parameters.Add("@Term", SqlDbType.VarChar).Value = textBox1.Text;
SqlDataReader dr = com.ExecuteReader();
DataTable dt = new DataTable ();
dt.Load(dr);
this.datagridview.datasource=dt;
conn.Close();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询