[讨论]谈谈连接database的区别
从数据库中读取一个表的纪录,我都是这么写的:dim ds as new dataset
dim sql as string="select * from student"
dim strconn as string="server=(local); database=databasename; User ID=sa; Password=;"
dim adp as new sqldataadapter(sql,strconn)
adp.fill(ds,"student")
但是我看了很多别人写代码是这样的:
dim ds as new dataset
dim sql as string="select * from student"
dim strconn as string="server=(local); database=databasename; User ID=sa; Password=;"
Dim da As New SqlDataAdapter
Dim comm As New SqlCommand
Dim conn As New SqlConnection(strconn)
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = str
da.SelectCommand = comm
conn.open
ds.fill(ds,"student")
我想问一下大家这两种有什么区别,那个好些?