我是新手,有这个问题.我可以使用sqlDataReader而不是Recordset.我想在sqlDataReader中实现以下结果.
Dim dbConn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim sqlstr As String = "SELECT Name,Status FROM table1 WHERE id=" + item_id.Value.ToString rs.Open(sql,dbConn) While Not rs.EOF txtName.Text = rs.Fields.Item("Name").Value ddlstatus.SelectedIndex = 1 rs.MoveNext() End While rs.Close() rs = Nothing dbConn.Close() dbConn = Nothing
强烈建议您使用使用模式:
Dim sConnection As String = "server=(local);uid=sa;pwd=PassWord;database=DatabaseName" Using Con As New sqlConnection(sConnection) Con.Open() Using Com As New sqlCommand("Select * From tablename",Con) Using RDR = Com.ExecuteReader() If RDR.HasRows Then Do While RDR.Read txtName.Text = RDR.Item("Name").ToString() Loop End If End Using End Using Con.Close() End Using