I'm having this error in this part of the code and I'm still unable to figure out a solution for it
Line 144: .CommandType = CommandType.Text Line 145: .Connection = cn
Line 146: dr = .ExecuteReader
Line 147: End With
Line 148 :
Public Function GetDBField(ByVal Query As String, ByVal Field As String) As String
'abriendo la conexion a la base de datos
SqlConnect()
Dim cmd As New SqlCommand Dim result As String = ""
Dim dr As SqlDataReader dr = Nothing
'ejecutando el lector de DO Try
With
cmd .CommandText = Query
.CommandType = CommandType.Text
.Connection = cn dr = .ExecuteReader
End With
Catch ex As SqlException ShowAlertMessage(ex.Message) GetDBField = Nothing Exit Function End Try
'Escribiendo en una Variable de texto Try If dr.HasRows Then
End If While dr.Read If IsDBNull(dr(Field).ToString) = True Then result = Nothing Else result = dr(Field).ToString End If End While Catch ex As SqlException ShowAlertMessage(ex.Message) GetDBField = Nothing Exit Function
End Try
'Cerrando la conexion de BD SqlDisconnect()
GetDBField = result End Function Really in need of any kind of help
#Region " Variables Globales" Public db As String = "repuestosdr" 'Public CnStr As String = "Driver={SQL Server Native Client 10.0};Server=localhost;Database=" & db & ";Uid=crivera;Pwd=crivera;" Public CnStr As String = ConfigurationManager.ConnectionStrings("SuoodConnection").ConnectionString '"Driver={SQL Server};Server=repuestosdr.db.10580944.hostedresource.com;Database="& db & ";Uid=" & db & ";Pwd=r34llyH4rd!;Port=1433;"
Public Logged As Boolean = False
Public Qry As String Public msg As New MsgBoxResult
Public ds As New DataSet Public dt As New DataTable Public dr As SqlDataReader Public cn As New SqlConnection() Public da As New SqlDataAdapter Public cmd As SqlCommand
#End Region for connection:
#Region " Connection" Public Function SqlConnect(Optional ByVal MyPage As Page = Nothing) As Boolean
Try
If cn.State = ConnectionState.Closed Then
With
cn .ConnectionString = CnStr .Open()
End With
End If
Catch myerror As Exception ShowAlertMessage("Error Connecting to the Database" & Chr(13) & myerror.Message)
SqlConnect = False
End Try
SqlConnect = True
End Function
Really in need of any kind of help.