T
tshad
I am a little confused here.
I was under the impression that before you can use an interface (and you
can't instantiate an interface), you have to implement all the methods.
But I am trying to set up a Generic DataBase class and this seems to work.
I am not instantiating the IDbConnection interface and am not defining any
of the methods (ChangeDatabase, Close, CreateCommand, Open).
In the following I am defining dbConn as an IDbConnection and am passing it
back as an IDbConnection type:
********************************************************************
Sub LoadGrid3()
Dim dbConn As IDbConnection = _
GetConnection("Persist Security Info=False;Data Source=AW;Initial
Catalog=Inter")
Dim dbCmd As SqlCommand = New SqlCommand("GetUsers", dbConn)
dbCmd.CommandType = CommandType.StoredProcedure
dbCmd.Parameters.Add("@UserID",SqlDBType.Int).value = 1
dbConn.Open()
DataGrid1.DataSource = dbCmd.ExecuteReader
DataGrid1.DataBind()
End Sub
Function GetConnection(ConnectString As String) As IDbConnection
Dim cnn As New SqlConnection(ConnectString)
return cnn
End Function
**************************************************************************
Why does this work????
Thanks,
Tom
I was under the impression that before you can use an interface (and you
can't instantiate an interface), you have to implement all the methods.
But I am trying to set up a Generic DataBase class and this seems to work.
I am not instantiating the IDbConnection interface and am not defining any
of the methods (ChangeDatabase, Close, CreateCommand, Open).
In the following I am defining dbConn as an IDbConnection and am passing it
back as an IDbConnection type:
********************************************************************
Sub LoadGrid3()
Dim dbConn As IDbConnection = _
GetConnection("Persist Security Info=False;Data Source=AW;Initial
Catalog=Inter")
Dim dbCmd As SqlCommand = New SqlCommand("GetUsers", dbConn)
dbCmd.CommandType = CommandType.StoredProcedure
dbCmd.Parameters.Add("@UserID",SqlDBType.Int).value = 1
dbConn.Open()
DataGrid1.DataSource = dbCmd.ExecuteReader
DataGrid1.DataBind()
End Sub
Function GetConnection(ConnectString As String) As IDbConnection
Dim cnn As New SqlConnection(ConnectString)
return cnn
End Function
**************************************************************************
Why does this work????
Thanks,
Tom