Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql help please.

Status
Not open for further replies.

Jacksparrow87

Technical User
Jun 29, 2008
93
GB
Hi people,

I was hoping someone could help me out here please, on my form I have a datagrid and a button and a few labels.

What I need to do is basically display all the information on the datagrid and at the same time have a certain row in the datagrid selected. So far I have the following coding:

Code:
 Dim conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\CNS.mdb")
        Dim adapter As New OleDbDataAdapter("Select * from Log WHERE LogNumber = " & lbllog.Text & " Order By LogNumber DESC, NoteNumber DESC; ", conn)
        Dim dt As New DataTable("Log")
        adapter.Fill(dt)
        dglog.DataSource() = dt
        dt.DefaultView.AllowNew = False

However what the above coding does is select the record which is correct but it only displays that row, however I want all the rows displayed but with that row selected.

Is this possible? Please help
 
Code:
Select * from Log WHERE [b][u]LogNumber = " & lbllog.Text & "[/u][/b] Order By LogNumber DESC, NoteNumber DESC;

Does this return multiple rows or just one when you execute it against the database directly? Looks like it is searching for a specific record not a group of records. Which would indicate that the WHERE clause is too specific.

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
I might not help much.. because it is 1-2 years that i last used DB programming and VB.

But,
The condition that displays the "correct" data is the WHERE clause. If you remove this only, all records will show up ( keep the ORDER BY clause).
You need to find out the row that has as LogNumber the lblLog.Text.

I think this can be handled by the datagridview control.

I can post later if i find something... or maybe somebody else replies fasteer.
 
Sorry yeah the Where clause in the statement only shows the records with that Log number, however I want to show all of the data but I want the datagrid to Select the top record with that log number.

Sorry but I cannot use a datagridview as Im using 2003 and that came out in 2005 I think.
 
Yes, it is in 2005 version.

So you want to show ALL logNumbers (and the rest columns) but for a SPECIFIC ONE ..select the most recent? I dont know what you have in database.

Maybe you can select a row (highlight it) using a criteria.
I'll take a look at the v2003 grid and hopefully there will be a method to call
 
To be honest I just want to display all the data in the datagrid but highlight a specific row which is displayed in lbllog.text.
 
Code:
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\CNS.mdb")
        Dim adapter As New OleDbDataAdapter([u][b]"Select * from Log  ORDER BY LogNumber DESC, NoteNumber DESC;[/b][/u] ", conn)

and then just set the Selected Row in the grid to equal lbllog.Text.

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
Hi,

Sorry if I didn't make my self clear and if you misunderstood me but that is the part I require help with.

My statement is the same as what you have stated above but I require help on the "and then just set the Selected Row in the grid to equal lbllog.Text" part as I dont know how to do this.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top