data manipulation

rangerbud249

Active member
Joined
Aug 18, 2004
Messages
27
Programming Experience
Beginner
I would like to make a simple query.

I have a dropdownlist and two text boxes. How can I query my sql server db using those 3 variables as the (where) criteria so that I can display the (select) part of it in a datagrid.

Therefore I need to connect to my db.
make the Select From Where Statement
and then Bind all that info to a datagrid.

Any help and code examples will be so very much appreciated.
Or If you can let me know what book offers how to do form (data manipulation) using a sql server for your connections. Problem with the books I have is that they offer these things just in different chapters and not as a whole project.


Jose
 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
I would try something like the following (assuming ASP.NET)

VB.NET:
    Dim DS As System.Data.DataSet
    Dim Con As System.Data.SqlClient.SqlConnection
    Dim Ada As System.Data.SqlClient.SqlDataAdapter
    Dim connStr as String
    Dim sqlStr as String

    conStr = "Your connection string"

    sqlStr = "SELECT (whatever) FROM (Wherever) WHERE Condition1 = '" & DropDown1.SelectedItem & "' And Condition2 = '" & DropDown2.SelectedItem & "' AND Condition3 = '" & TextBox1.Text & "' AND Condition4 = '" & TextBox2.Text & "'"
    Con = New System.Data.SqlClient.SqlConnection(connStr)
    
    Ada = New System.Data.SqlClient.SqlDataAdapter(sqlStr, Con)
    
    DS = New System.Data.DataSet()
    Ada.Fill(DS, "Table1")    
    
    'Fill the DataGrid
    DataGrid1.DataSource = DS.Tables("Table1").DefaultView
    DataGrid1.DataBind()
 
Top Bottom