请问vs2005中如何将select结果输出到gridview?无分了,请求爱心帮助。。。
下列代码在VS2003下成功输出到WEB页面:Dim oCmd As SqlClient.SqlCommand
Dim strConn As String
strConn = "Data source=(local);"
strConn &= "initial catalog=gzgl;"
strConn &= "user id=sa;"
strConn &= "password=lifan"
oCmd = New SqlClient.SqlCommand
oCmd.Connection = New SqlClient.SqlConnection(strConn)
oCmd.Connection.Open()
oCmd.CommandText = "select * from gz"
Dim myreader As SqlClient.SqlDataReader = Nothing
myreader = oCmd.ExecuteReader()
datagrid1.DataSource = myreader
datagrid1.DataBind()
myreader.Close()
oCmd.Connection.Close()
在VS2005下改为以下代码后,经过测试,能执行SQL命令,但不能将select结果在gridview输出(我需要手动能配置select命令的,到目前为止,还没发现VS2005数据源自动配置能满足我的要求),实在不知道怎么改了,请求帮助!万分感谢!
Dim oCmd As Data.SqlClient.SqlCommand
Dim strConn As String
strConn = "Data source=(local);"
strConn &= "initial catalog=gzgl;"
strConn &= "user id=sa;"
strConn &= "password=lifan"
oCmd = New Data.SqlClient.SqlCommand
oCmd.Connection = New Data.SqlClient.SqlConnection(strConn)
oCmd.Connection.Open()
oCmd.CommandText = "select * from gz"
Dim myreader As Data.SqlClient.SqlDataReader = Nothing
myreader = oCmd.ExecuteReader()
GridView1.DataSource = myreader
GridView1.DataBind()
myreader.Close()
oCmd.Connection.Close()
--------------------编程问答-------------------- 顶一下,在线等.... --------------------编程问答-------------------- sqldataaccess sda = new sqldataaccess();
dataset ds = new dataset();
ds = sda.getdataset(sql);
this.gridview.datasource = ds;
this.gridview.databind();
前提是要写一个getdataset方法
补充:.NET技术 , ASP.NET