Running SQL Queries in VB.Net2003

Joined
Jan 20, 2006
Messages
6
Programming Experience
Beginner
Hi to every one in the Forum. I am working on a college Project in which I am using VB.NET 2003 & SQL Server2000. I am facing a very silly error in Running SQL Queries. I am not able to Run SQL Queries in which 'AND' is used :p . What I want is that when a button is clicked Query should Run & Datagrid should be filled with filtered database. eg: To run simple Querie like​
SELECT *
FROM Emp_Information
WHERE (Emp_Id=?)
what I am coding in VB.Net is:-
SqlDataAdapter2.SelectCommand.Parameters("@param2").Value = TextBox1.Text
DataGrid1.DataSource = DataSet81
DataGrid1.DataMember = "Emp_Information"
DataSet81.Clear()
SqlDataAdapter2.Fill(DataSet81)


But What should be the coding in VB.Net to use
SELECT *
FROM Cust_Database
WHERE (FName=?) AND (Date_of_Order=?)

in this case FName & Date_of_Order will be entered in TextBox3 & TextBox6 respectively
 

TechGnome

Well-known member
Joined
May 23, 2005
Messages
896
Programming Experience
10+
If you create and add the parameters in the same order they are in the query, you should be OK.

-tg
 
Joined
Jan 20, 2006
Messages
6
Programming Experience
Beginner
Clarification on your Reply (Running SQL Queries) Sir.

Do you want to say that I should use :confused:

SqlDataAdapter2.SelectCommand.Parameters("@param2" ).Value = TextBox1.Text AND SqlDataAdapter2.SelectCommand.Parameters("@param7" ).Value = TextBox2.Text

DataGrid1.DataSource = DataSet81

DataGrid1.DataMember = "Emp_Information"
DataSet81.Clear()
SqlDataAdapter2.Fill(DataSet81)

I am Sorry if this Irritates you :eek:
 

TechGnome

Well-known member
Joined
May 23, 2005
Messages
896
Programming Experience
10+
manpreetdhawan said:
Do you want to say that I should use :confused:

SqlDataAdapter2.SelectCommand.Parameters("@param2" ).Value = TextBox1.Text AND SqlDataAdapter2.SelectCommand.Parameters("@param7" ).Value = TextBox2.Text

DataGrid1.DataSource = DataSet81

DataGrid1.DataMember = "Emp_Information"
DataSet81.Clear()
SqlDataAdapter2.Fill(DataSet81)

I am Sorry if this Irritates you :eek:
On two lines like this:
VB.NET:
SqlDataAdapter2.SelectCommand.Parameters("@param2" ).Value = TextBox1.Text
SqlDataAdapter2.SelectCommand.Parameters("@param7" ).Value = TextBox2.Text

But yep... just like that...

-tg

ps: a rock in my shoe is irritating.... you're not a rock, and this isn't my shoe...
 
Joined
Jan 20, 2006
Messages
6
Programming Experience
Beginner
Thank You TechGnome

Thank you TechGnome For your Help :) .
I just want to ask that for other keywords like OR instead of AND is the procedure same, or different for every keyword. But Never the less Thank You for Your Help ;)
 

TechGnome

Well-known member
Joined
May 23, 2005
Messages
896
Programming Experience
10+
The operators and the number of them are irrelevant....

As long as you supply the number of parameters that the query is expecting, and the SQL is correct, it all falls into place quite easily.

-tg
 
Top Bottom