
winform datagridview显示数据库里的视图
要怎么样写,把数据库里建好的视图xxx_view的结果显示到winfrom的datagridview控件里面来呢?比如privatevoidfrmmain_Load(ob...
要怎么样写,把数据库里建好的视图xxx_view的结果显示到
winfrom的datagridview控件里面来呢?
比如
private void frmmain_Load(object sender, EventArgs e)
{
this.datagridview1.DataSource =
}
string sqlCheckStr = "select * from xxx_view";
SqlConnection cn = new SqlConnection();
da1 = new SqlDataAdapter(sqlCheckStr, datacon.getcon());
da1.Fill(ds, "Table");
gvdata.DataSource = ds.Tables["Table"];
原来把这个视图当表用就可以了。 展开
winfrom的datagridview控件里面来呢?
比如
private void frmmain_Load(object sender, EventArgs e)
{
this.datagridview1.DataSource =
}
string sqlCheckStr = "select * from xxx_view";
SqlConnection cn = new SqlConnection();
da1 = new SqlDataAdapter(sqlCheckStr, datacon.getcon());
da1.Fill(ds, "Table");
gvdata.DataSource = ds.Tables["Table"];
原来把这个视图当表用就可以了。 展开
展开全部
String strconn = String.Format(@"Data Source=.;Initial Catalog=数据库名称;User ID=sa;Password=;TimeOut=0");
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
try
{
SqlDataAdapter sda = new SqlDataAdapter();
String strsql=String.Format(@"select * from xxx_view");
SqlCommand cmd = new SqlCommand(strsql, conn);
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
//我的这些控件都没有该名称的用的默认的名字,你自己替换下
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("载入出错!原因为:"+ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
//这些代码放到你的frmmain_Load事件里就好了
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
try
{
SqlDataAdapter sda = new SqlDataAdapter();
String strsql=String.Format(@"select * from xxx_view");
SqlCommand cmd = new SqlCommand(strsql, conn);
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
//我的这些控件都没有该名称的用的默认的名字,你自己替换下
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("载入出错!原因为:"+ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
//这些代码放到你的frmmain_Load事件里就好了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询