12-12-2013 11:27 AM
Hi,
I am populating datagrid with data from external database table. Grid will show empty even after grid refresh.
But, records show only after scroll up. I am not sure what is missing?
I set KeyField property and populating grid via code using Recordset. I attached document explaining issue.
I really appreciate for any clue.
Sub PopulateCustomers(strSearch)
Dim strDBServer,strDB,strLogin,strPassword, strConn, objRS, cn, strSQL
strDBServer = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSDBServer'")
strDB = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSDB'")
strLogin = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSLogin'")
strPassword = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSPWD'")
strConn = "Provider = SQLOLEDB; Data Source = " & strDBServer & "; Initial Catalog = " & strDB & "; User Id = " & strLogin & "; Password = " & strPassword & ";"
Set cn = CreateObject("ADODB.Connection")
cn.Open strConn
If Err.Number <> 0 Then
Msgbox Err.Source & ": " & Err.Description, 0, "Error in connecting to RFMS Database!"
Err.Clear
Exit Sub
End If
if(strSearch<>"") then
strSQL = "select Top 100 'F' as Tag,SeqNum,Cust_Name from Customer WHERE Cust_name Like '" & strSearch & "%'"
else
strSQL = "select Top 100 'F' as Tag,SeqNum,Cust_Name from Customer"
END IF
' if(strSearch<>"") then
'' strSQL = "select Top 100 SeqNum,Cust_Name from Customer WHERE Cust_name Like '" & strSearch & "%'"
'else
'' strSQL = "select Top 100 SeqNum,Cust_Name from Customer"
' END IF
Set objRS = CreateObject("ADODB.Recordset")
With objRS
Set .ActiveConnection = cn
.Open strSQL
End With
CreateGridRecordSet dgCustomers
while Not objRS.EOF
With dgCustomers.Recordset
.AddNew
.Fields("TAG").Value = objRS.Fields("TAG").Value
.Fields("SEQNUM").Value = objRS.Fields("SEQNUM").Value
.Fields("CUST_NAME").Value = objRS.Fields("CUST_NAME").Value
.Update
End With
objRS.MoveNext
wend
dgCustomers.Refresh
objRS.Close
Set objRS = Nothing
End Sub
12-12-2013 12:04 PM