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 -
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?
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?
rachayita jaiswalPosted Jul 11, 2013, 5:12 AM
Kunal VaishyaPosted Jul 11, 2013, 4:35 AM
One more way You can call your function by like this
string query = "select * from dbo.Function1(1,2);";
Kunal VaishyaPosted Jul 11, 2013, 4:34 AM
You can call your function by like this
string query = "select * from dbo.Function1(@pa1,@par2);";
cmd.Parametes.Add("@par1", SqlDbType.Int).Value = 2);
cmd.Parametes.Add("@par2", SqlDbType.Int).Value = 1;