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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Data 1

Status
Not open for further replies.

kimtp

Programmer
Jun 15, 2002
310
US
With a click in a treeview the records populate a datagrid. Each record has 3 fields; an ID, Title and length. When a record is clicked in the datagrid three
text boxes are filled with the data for editing. There are 2 areas of concern:

1. When the datagrid is clicked the first time the first record is the one that shows up in the textboxes. If the record is clicked twice the correct record is displayed in the textboxes.

2. If the record has an apostrophe, a BOF/EOF error msg appears even though there is a replace statement.

My code for the datagrid:
Code:
Dim sName As String
    sName = datagrid1.Text
    sName = Replace(datagrid1.Text, "'", "")
    sSql = "SELECT TrackID, Title, Length FROM tblTracks WHERE Title = '" & sName & "'"
    If rst.State = adStateOpen Then rst.Close
    rst.Open sSql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    txtTrack.Text = rst.Fields("TrackID").Value & ""
    txtTitle.Text = rst.Fields("Title").Value & ""
    txtLength.Text = rst.Fields("Length").Value & ""
Is the datagrid the best way to display the info or should I use the flexgrid?
Andy ideas would be great. thanx.
 
If the field in the database actually does contain a single quote then eliminating it will cause the SQL to miss it. You should change

sName = Replace(datagrid1.Text, "'", "")

to

sName = Replace(datagrid1.Text, "'", "''")

i.e. Convert a single quote to double quotes.
 
Another set of eyes is always helpful. Thought I had the single quotes inside the double.

Any ideas on how to get the right record to show up after only one click?

Thanx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top