By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,734 Members | 832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,734 IT Pros & Developers. It's quick & easy.

SELECT * FROM[Table]WHERE field BETWEEN...

P: n/a
lea

Does anyone know how to write the
SELECT * FROM tblename WHERE fldname BETWEEN combobox1.text AN
combobox2.text
i can't find much source about this query on net,i need to let use
select category to print report.Please help me,THank

--
le
-----------------------------------------------------------------------
lea's Profile: http://www.msusenet.com/member.php?userid=156
View this thread: http://www.msusenet.com/t-187052994

Nov 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
May be so... (for oledb provider)
OleDbConnection conn = new OleDbConnection (connStr);
string cmdText = "SELECT * FROM tblename WHERE fldname BETWEEN @begintext
AND @endtext";

OleDbCommand cmd = new OleDbCommand (cmdText, conn);
cmd.Parameters.Add ("begintext", combobox1.text);
cmd.Parameters.Add ("endtext", combobox2.text);
conn.Open ();
// Or You may fill in dataset using dataadapter
OleDbDataReader reader = cmd.ExecuteReader ();

while (reader.Read())
{
// do what You want
}
reader.Close ();
conn.Close ();
Nov 22 '05 #2

P: n/a
lea

thank you! i solved the problem.but is there possible to insert all th
"dr.item" into database before the datareader.close(between whil
dr.read and end while)? i facing problem state that should close th
connection and recreate a new connection for the INSERT INTO query. bu
what i want is retrieve the record(i did it) and INSERT the records tha
i retrieve into a temporary table for printing purposes(crysta
report).
instead of using the method that i mentioned above, is there any othe
way to print the records that i retrieved

--
le
-----------------------------------------------------------------------
lea's Profile: http://www.msusenet.com/member.php?userid=156
View this thread: http://www.msusenet.com/t-187052994

Nov 22 '05 #3

P: n/a
Sorry, but i don;t understande Your message clear.... :(
I'll answer what I understood:
At first You don't need to close a connection to insert raws into some
table, just close reader...

Second, if You want just to create temporary table, you can use following
approach:

OleDbConnection conn = new OleDbConnection (connStr);
string cmdText = "SELECT * FROM tblename WHERE fldname BETWEEN @begintext
AND @endtext";

OleDbCommand cmd = new OleDbCommand (cmdText, conn);
cmd.Parameters.Add ("begintext", combobox1.text);
cmd.Parameters.Add ("endtext", combobox2.text);
OleDbDataAdapter dbAdapter = new OleDbAdapter (cmd);
DataTable tempTable = new DataTable ();
dbAdapter.Fill (tempTable);
conn.Close ();
tampTable - is what You need
Nov 22 '05 #4

P: n/a
lea

erm... this concept is quite close to what i post. :) but my project du
date is 15/JUN. I'd Pass up my system. Im using crystal report, but i
show all the data in the table.. this is not what i want. but time i
limited. However, thanks for your help, i will try this code after m
exam! :rolleyes: THANKS!

--
le
-----------------------------------------------------------------------
lea's Profile: http://www.msusenet.com/member.php?userid=156
View this thread: http://www.msusenet.com/t-187052994

Nov 22 '05 #5

P: n/a
lea

erm... this concept is quite close to what i post. :) but my project du
date is 15/JUN. I'd Pass up my system. Im using crystal report, but i
show all the data in the table.. this is not what i want. but time i
limited. However, thanks for your help, i will try this code after m
exam! :rolleyes: THANKS!

--
le
-----------------------------------------------------------------------
lea's Profile: http://www.msusenet.com/member.php?userid=156
View this thread: http://www.msusenet.com/t-187052994

Nov 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.