Hi Cor,
I am getting the data from the query every time I display the grid. It
works on the first run of the form. If I close the form and open the form
by clicking on the button again, the datagrid doesnt get displayed but it
shows a record count in a messagebox.
If I get data from the query the first time and it displays why wont it
display the second time running the same procedure call?
Where in my program do you think the data is not there anymore? I'm using a
"Select * from table" as SqlQuery.
---Getting the data from the database----
conn = New SqlConnection(UserInfoClass.sconn)
daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
daRoleDetail.Fill(dsClass, TableName
---setting the datagrid datasource with the dataset------
Me.dgClass.SetDataBinding(dsClass, TableName)
thanks,
Will
"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> WK6pack,
>
> A datagrid does not hold data, it is displaying it only from its
> datasource. (the binding to that)
>
> If the data is not anymore there (as it seems to me in your program), the
> datagrid will as well not dispay that.
>
> Cor
>
> "wk6pack" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> Hi,
>>
>> I have a datagrid that is populated from a query in SQL Server. The
>> first time I run the form, it appears, I make changes or view it and it
>> is fine. When I close the form and open it up again, the datagrid is not
>> there to see. I'm running the same code to populate it. What is
>> happening? Any suggestions?
>>
>> thanks,
>> Will
>>
>> Here is the code.
>>
>>
>>
>> Dim ProcName As String = "PopulateDataGrid"
>>
>> Dim daRoleDetail As SqlDataAdapter
>>
>> Dim conn As SqlConnection
>>
>> dsClass.Clear()
>>
>> Me.dgClass.TableStyles.Clear()
>>
>> Try
>>
>> conn = New SqlConnection(UserInfoClass.sconn)
>>
>> daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
>>
>> daRoleDetail.Fill(dsClass, TableName)
>>
>>
>>
>> Dim ts As New DataGridTableStyle
>>
>> ts.MappingName = TableName
>>
>> ts.AlternatingBackColor = Color.WhiteSmoke
>>
>> ts.SelectionBackColor = Color.Yellow
>>
>> ts.SelectionForeColor = Color.Red
>>
>> ts.PreferredRowHeight = 22
>>
>> Dim colID As New DataGridTextBoxColumn
>>
>> Dim colRoleDetail As New DataGridTextBoxColumn
>>
>> Dim colclass As New DataGridTextBoxColumn
>>
>> Call setDataGridProps(colID, "RoleDetailID", "ID", "", 75)
>>
>> Call setDataGridProps(colRoleDetail, "RoleDetail", "Role Detail", "",
>> 100)
>>
>> Call setDataGridProps(colclass, "class", "Class", "", 200)
>>
>> ts.GridColumnStyles.Add(colRoleDetail)
>>
>> ts.GridColumnStyles.Add(colclass)
>>
>> Me.dgClass.TableStyles.Add(ts)
>>
>> ts = Nothing
>>
>> Me.dgClass.SetDataBinding(dsClass, TableName)
>>
>> Me.displayMsg(CStr(dsClass.Tables(TableName).Rows.Count) & " " &
>> TableName & " Records Loaded")
>>
>> 'clean up resources
>>
>> If Not conn Is Nothing Then
>>
>> conn.Close()
>>
>> conn.Dispose()
>>
>> End If
>>
>> If Not daRoleDetail Is Nothing Then daRoleDetail.Dispose()
>>
>>
>
>
|