Private Sub GetData() Dim cmd As New SqlCommand("select classid,classname,startyear,isfinish,employeename from class left join employee on class.employeeid=employee.employeeid where class.schoolid=@schoolid and isfinish='否'order by classid desc", cnn) cmd.Parameters.Add("@schoolid", Session("schoolid")) Dim adapter As New SqlDataAdapter(cmd) Dim dst As New DataSet Try adapter.Fill(dst) dgdClass.DataSource = dst.Tables(0).DefaultView dgdClass.DataBind() Catch ex As Exception Response.Write(ex.Message) Finally cnn.Close() End Try
dim cmd as adodatasetcommandasp.net没有"adodatasetcommand"吗?为什么会报错?请高手指点迷津!用vb.net怎么开发?
msdn里面的例子,应该可以满足你的要求了 Public Shared Sub Main() Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;" & _ "Integrated Security=SSPI;Initial Catalog=northwind") Dim catCMD As SqlCommand = nwindConn.CreateCommand() catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories" nwindConn.Open() Dim myReader As SqlDataReader = catCMD.ExecuteReader() Do While myReader.Read() Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1)) Loop myReader.Close() nwindConn.Close() End Sub
1,建议楼主还是先看看Ado.net方面的知识 2,VB.net跟C#开发也差不多的
上面说的没错,应该是ado.net的问题 dim cmd as adodatasetcommandasp.net没有"adodatasetcommand"吗?为什么会报错?请高手指点迷津!用vb.net怎么开发?adodatasetcommand应该是sqlcommane不过有些书写的ado和sql不同,与数据库有关。 对吗?
//asp.net没有"adodatasetcommand"吗?为什么会报错? 你的书可能是Beta版的,里边用的名称和标准版有些是不同的,建议换一本:) 以前的using System.Data.ADO应改为using System.Data.OleDb; using System.Data.Sql;应改为using System.Data.SqlClient; 以前的datasetcommand现在叫dataAdapter,所以呀,换本书看吧
Dim cmd As New SqlCommand("select classid,classname,startyear,isfinish,employeename from class left join employee on class.employeeid=employee.employeeid where class.schoolid=@schoolid and isfinish='否'order by classid desc", cnn)
cmd.Parameters.Add("@schoolid", Session("schoolid"))
Dim adapter As New SqlDataAdapter(cmd)
Dim dst As New DataSet
Try
adapter.Fill(dst)
dgdClass.DataSource = dst.Tables(0).DefaultView
dgdClass.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
Finally
cnn.Close()
End Try
Public Shared Sub Main()
Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;" & _
"Integrated Security=SSPI;Initial Catalog=northwind") Dim catCMD As SqlCommand = nwindConn.CreateCommand()
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories" nwindConn.Open() Dim myReader As SqlDataReader = catCMD.ExecuteReader() Do While myReader.Read()
Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
Loop myReader.Close()
nwindConn.Close()
End Sub
2,VB.net跟C#开发也差不多的
dim cmd as adodatasetcommandasp.net没有"adodatasetcommand"吗?为什么会报错?请高手指点迷津!用vb.net怎么开发?adodatasetcommand应该是sqlcommane不过有些书写的ado和sql不同,与数据库有关。
对吗?
你的书可能是Beta版的,里边用的名称和标准版有些是不同的,建议换一本:)
以前的using System.Data.ADO应改为using System.Data.OleDb;
using System.Data.Sql;应改为using System.Data.SqlClient;
以前的datasetcommand现在叫dataAdapter,所以呀,换本书看吧