sql - Import specific row from access database -
at current have 5 textboxes wish populate first 5 rows of column in access database.
i have attempted several different sql queries, no success.
here's working code first box:
try dim con new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=c:\test\response.mdb;") dim cmd new oledbcommand con.open() cmd.connection = con cmd.commandtext = "select * question" cmd.prepare() dim trace = cmd.executereader trace .read() q1txt.text = .item("questiontext") .close() end catch end try
that code works fine, when try expand on include next 4, can't work or find information can me.
i've tried writing diffrent query populate each box using
select * question limit n-1, 1
and
select top 1 field question
amongst dozens of others throw 1 exception or another.
does know of way alter code can tell it:
select top 5 question q1txt.text = .item("row1") q2txt.text = .item("row2") q3txt.text = .item("row3") q4txt.text = .item("row4") q5txt.text = .item("row5")
thank steve helping me out this! code using here:
dim boxes = {q1txt, q2txt, q3txt, q4txt, q5txt} dim index integer = 0 using con = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=c:\test\response.mdb;") using cmd = new oledbcommand("select top 5 * question", con) con.open() using trace = cmd.executereader each item in boxes trace .read() boxes(index).text = .item("questiontext") index += 1 end next end using end using end using
access doesn't have limit keyword mysql. order on column , take top 5 columns. don't know if have kind of column can ordered, show code without order clause fetching first 5 records in whichever order database give them
dim boxes = new textbox() {q1text, q2text, q3text, q4text, q5text } dim index integer = 0 using con = new oledbconnection(".....") using cmd = new oledbcommand("select top 5 * question", con) con.open() using trace = cmd.executereader while trace.read() boxes(index).text = trace.item("questiontext") index += 1 end while end using end using end using
at every read have different record place in different textbox, have built array of textboxes , used index fill correct box
notice have added using statement around disposable objects sure correctly closed , disposed
Comments
Post a Comment