Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually now i am working in Datagrid.

i am trying to bind a records.

First time record binding properly displayed but 2 time record is binding 1st record was deleted.
I want to add 2nd record.

if i try 3 time binding need to add 3 row and i am binding through sql Query.
Query is working fine. i am getting data to datatable also.

If any one Help me..
VB
public dt As DataTable

VB
Private Sub btnADD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnADD.Click
       Dim sql As String = "select * from court where courtid='" & ddlfromsec.SelectedValue & "'"
       dt = class.Bysql(sql)
       If dt.Rows.Count > 0 Then
           dg1.DataSource = dt
           dg1.DataBind()
       End If
   End Sub



I will Change ddlfromsec.SelectedValue. first time one value, 2nd line one value like that.
Posted
Updated 15-Mar-13 23:38pm
v5
Comments
frostcox 15-Mar-13 6:08am    
Can you show you code so I can see whats going on
Nelek 15-Mar-13 9:23am    
Question was updated with code, you can check
nane aa 15-Mar-13 6:28am    
Check Now.
frostcox 15-Mar-13 10:35am    
CHill60 is right, you are always only going to return 1 record with your SQL query, you need to change this and your code will be fine.
Chinmaya C 16-Mar-13 13:07pm    
Dim sql As String = "select * from court where courtid='" & ddlfromsec.SelectedValue & "'"

As per my understanding form the posted code, you are applying equal operator on primarykey field (courtid), it always returns only one record, and thus shows only one record everytime.

try with the following:

Dim sql As String = "select * from court"

1 solution

You're creating a new datatable each time so it will only contain a single row.
Either just add rows to the dgv instead of using databinding
or
Don't create a new datatable each time and add rows to a datatable defined outside the sub
 
Share this answer
 
Comments
nane aa 16-Mar-13 5:39am    
OK.. I given dt in public now but i am getting same problem.. dt rows are deleted..
CHill60 18-Mar-13 6:48am    
ADD rows to a datatable not just define the datatable outside the sub. However using the IN clause as per your last comment also works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900