hello there
what exact thing i got from the question is that you just don't want to create stored procedures and want to pass the queries to the functions created.
but this will not be the exact way this stuff suppose to be done by the way you can do that by creating a class (like data Access layer) where you can put all the classes responsible for all the things like :
create a conClass.cs or you can add a class project to the app you are working on : create a class which will open the connection to the database. now if you want a function which will accept a Query as string and will execute it do it like:
Public Sub ExecutQuery(ByVal qry As String)
Try
ConOpen()
cmd = New SqlCommand(qry, con)
cmd.ExecuteNonQuery()
ConClose()
Catch ex As Exception
ConClose()
ErrMsgBox(ex.Message)
End Try
End Sub
so now to execute a qury you have to write all the time the following code :
create a instance of this class on the form
dim con as new conClass
and where you want to execute the query write :
con.ExecutQuery("QueryHere")
this code will execute the passed querry what ever it will be (save, update, delete etc.). like this way you can create the other methods like to bind the dropdown list, Datagrid view or any other control.
and to return an array :
Public Function Ret_Array(ByVal qry As String, ByRef values() As Integer)
Dim i As Integer
Try
ConOpen()
cmd = New SqlCommand(qry, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
If dr.HasRows = True And IsDBNull(dr) = False Then
While dr.Read()
If Not IsDBNull(dr.Item(0)) Then
ReDim Preserve values(i)
values(i) = dr.Item(0)
i = i + 1
End If
End While
Else
End If
dr.Close()
ConClose()
Catch ex As Exception
ErrMsgBox(ex.Message)
End Try
Return Nothing
End Function
if this is not what you are expecting as an answer just let me know but if yes then i will provide you the C# code.
Best Regards.