英文:
How to get DataTable in vb.net using sql Connection
问题
以下是您要翻译的代码部分:
Dim oConnString As String
Dim strQuery As String
Dim myConn As SqlConnection
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim results As String
oConnString = "Data Source=" + strServerName + "; Database='" + strDatabaseName + "';Integrated Security=true"
Dim oConnection As SqlConnection = New SqlConnection(oConnString)
strQuery = "SELECT * from Usertable"
myCmd = oConnection.CreateCommand
myCmd.CommandText = strQuery
oConnection.Open()
myReader = myCmd.ExecuteReader()
'Some codes here'
myReader.Close()
myConn.Close()
请注意,代码中的注释部分未包括在内。
英文:
Dim oConnString As String
Dim strQuery As String
Dim myConn As SqlConnection
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim results As String
oConnString = "Data Source=" + strServerName + "; Database='" + strDatabaseName + "';Integrated Security=true"
Dim oConnection As SqlConnection = New SqlConnection(oConnString)
strQuery = "SELECT * from Usertable"
myCmd = oConnection.CreateCommand
myCmd.CommandText = strQuery
oConnection.Open()
myReader = myCmd.ExecuteReader()
'Some codes here'
myReader.Close()
myConn.Close()
'===============================================================================================
Any idea on this error?
I encountered an error during processing this line "myReader = myCmd.ExecuteReader()"
Error:
"Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Additional information: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
i am expecting to read all the column in the database.
答案1
得分: 0
设置命令超时:
myCmd.CommandTimeout = 5*60 '5分钟
从阅读器获取数据表:
Dim myReader = cmd.ExecuteReader()
Dim dataTable = New DataTable()
dataTable.Load(myReader)
英文:
Try setting the command timeout
myCmd.CommandTimeout = 5*60 '5 min
To get a DataTable from the reader:
Dim myReader = cmd.ExecuteReader()
Dim dataTable = New DataTable()
dataTable.Load(myReader)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论