3
Answers

Dynamic Function using MySql and VB.Net

Ask a question
I have one function - 
 Public Function GetDataTable(ByVal Query As String) As DataTable
        Dim dtConnection As New OdbcConnection(ConfigurationManager.ConnectionStrings("DBConnection").ToString)
        dtConnection.Open()
        Dim dtTable As New DataTable
        Dim da As OdbcDataAdapter
        da = New OdbcDataAdapter(Query, dtConnection)
        da.Fill(dtTable)
        da.Dispose()
        dtConnection.Close()
        Return dtTable
    End Function

i am using this funtion in my code behind file like this - 

QryStr = "select * from table where UName='" & txtUserName.Text & "'and pwd='" & txtPassword.Text & "'"
dtUsers = DBClass.GetDataTable(QryStr)

so where ever i want to fetch data from database, i am using this function but here statically i am passing query.

i want to pass stored procedure in place of query so how will i create function with parameters so that i will use that function anywhere in application?

Answers (3)