rachayita jaiswal

rachayita jaiswal

  • NA
  • 217
  • 106.8k

Dynamic Function using MySql and VB.Net

Jul 11 2013 3:29 AM
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)