Rowdata not visible in telerik radGrid view - vb.net

I have a RasGridView with 2 rows of data fetched from SQL to be displayed in the grid.
If oSQL.IsConnected Then
Try
ds = oSQL.GetDataSet("Select * from calc_umns order by calc_id", CommandType.Text)
If ds.Tables(0).Rows.Count > 0 Then
ds.Tables(0).TableName = "getSavedCalc"
RadGridView1.MasterGridViewTemplate.AutoGenerateColumns = False
RadGridView1.DataSource = ds
RadGridView1.DataMember = "getSavedCalc"
End If
Catch ex As Exception
End Try
End If
But the grid shows two rows with no data in it. could anyone guide where I am going wrong?

The FieldName property should be SET unique name and field value doesn't correspond to the SQL column names only FieldName property does.

Related

Data grid view with combo box , add rows from data table

Search and display data in data grid view
Dim cmd As New OracleCommand("Select JV_CODE,JV_ACC_NAME,DEBIT,CREDIT From VOUCHER_DETAIL where VOUCHERNO =:Vno", sgcnn)
cmd.Parameters.Add("#Vno", OracleDbType.NVarchar2).Value = txtJVNo.Text.ToString.Trim
Dim daVD As New OracleDataAdapter(cmd)
Dim dtVD As New DataTable()
daVD.Fill(dtVD)
dgvAccDetail.AutoGenerateColumns = False
dgvAccDetail.DataSource = dtVD
dgvAccDetail.Rows(0).Cells(0).Value = dtVD.Rows(0).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(0).Cells(1).Value = dtVD.Rows(0).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(0).Cells(2).Value = dtVD.Rows(0).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(0).Cells(3).Value = dtVD.Rows(0).Item("CREDIT").ToString.Trim
Catch ex As Exception
MsgBox(ex.Message)
End Try
There are two rows in dtVD data table but result shows only one I stack with this some can tell what I'm doing wrong ?
The reason for this is that you are only assigning the one row. You have a couple options:
First, this code below here shouldn't really be necessary, of you setup the property binding on the grid. You'll get better performance that way if you use a bind. You don't have your GUI code here, but essentially your DataPropertyName field on the columns should be set.
dgvAccDetail.Rows(0).Cells(0).Value = dtVD.Rows(0).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(0).Cells(1).Value = dtVD.Rows(0).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(0).Cells(2).Value = dtVD.Rows(0).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(0).Cells(3).Value = dtVD.Rows(0).Item("CREDIT").ToString.Trim
If you insist on manually assigning the cell values, you cannot just do row 0 (that's the first row). You need to do all the rows in a loop.
For i as Integer = 0 to dtVD.Rows.Count - 1
dgvAccDetail.Rows(i).Cells(0).Value = dtVD.Rows(i).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(i).Cells(1).Value = dtVD.Rows(i).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(i).Cells(2).Value = dtVD.Rows(i).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(i).Cells(3).Value = dtVD.Rows(i).Item("CREDIT").ToString.Trim
Next

VB.NET listbox won't display list items

lstSafaris.DataSource = Nothing
lstSafaris.Items.Clear()
lstSafaris.Refresh()
lstSafaris.Items.Add("No unclosed safaris")
lstSafaris.DrawMode = DrawMode.Normal
Try
Helpers.openConnection(sqlConn)
Dim sqlCmd As New SqlCommand("closingTables", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
Dim sqlDA As New SqlDataAdapter(sqlCmd)
sqlDA.Fill(sqlDS)
For counter As Integer = 0 To sqlDS.Tables(1).Rows.Count - 1
listSource.Add(sqlDS.Tables(1).Rows(counter).Item("allocation_id"), sqlDS.Tables(1).Rows(counter).Item("file_number"))
Next
If listSource.Count > 0 Then
lstSafaris.DataSource = New BindingSource(listSource, Nothing)
lstSafaris.ValueMember = "Key"
lstSafaris.DisplayMember = "Value"
End If
lstSafaris.Refresh()
sqlConn.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
So guys that is my code for the Listbox, this is a Sub that is called when the program is launched and whenever the whole form is refreshed, so when the problem first runs it works fine but the problem is when the form is refreshed, it displays count is greater than one but its blank, it's like all the items are there but they are not displayed, what am I missing?
If listSource.Count > 0 Then
lstSafaris.DataSource = New BindingSource(listSource, Nothing)
lstSafaris.ValueMember = "Key"
lstSafaris.DisplayMember = "Value"
lstSafaris.DataBind()
End If
you need to bind the data and not need to refresh data or clear the Items just remove data source before assign any data to data source as shown below.
lstSafaris.DataSource = Nothing
If blank spots are showing up then it would seem like the binding is there, but the data isn't. I would do a quick-watch on your listsource dictionary after populating it and make sure that it is filled with data. If it has data then your
lstSafaris.ValueMember = "Key"
lstSafaris.DisplayMember = "Value"
lstSafaris.DataSource = New BindingSource(listSource, Nothing)
should work

new records to add first row of datagrid view in vb.net

In my VB.Net application I am filling my data grid view like this:
Dim cmdd1 As New SqlCommand("DashBordFetch1", con.connect)
cmdd1.CommandType = CommandType.StoredProcedure
cmdd1.Parameters.Add("#locid", SqlDbType.Int).Value = locid
da1.SelectCommand = cmdd1 dr = cmdd1.ExecuteReader
While dr.Read
flag = False
carid1 = dr("Car_Id")
For j = 0 To dcnt1 - 2
If carid1 = dgv.Item(0, j).Value Then
flag = True
Exit For
End If
Next
If flag = False Then
If dr("Car_Id") Is DBNull.Value Then
carid1 = "null"
Else
carid1 = dr("Car_Id")
End If
If dr("Plate_Source") Is DBNull.Value Then
platesource1 = "Null"
Else
platesource1 = dr("Plate_Source")
End If
Dim row1 As String() = {carid1, platesource1}
DGVDeliverd.Rows.Add(row1)
End If
End While
..also i am using Timer..every 2 minutes timer will work .some time new records will added to my datagridview..while adding new record that is adding to last row of my datagrid view,,i want to add every time new records to my first row of datagridview. how i can do this?
I am using windows forms
You can use Insert instead of Add to specify the position for the new row. So always insert at position zero:
DGVDeliverd.Rows.Insert(0, row1)
See MSDN here for details (screenshot below).
Use:
Order by your primary id desc
to keep the latest data on top of the grid
update #1
DGVDeliverd.Controls[0].Controls.AddAt(0, row1);

Count how many rows are in the dataset then display as text in a textbox?

How can I count how many rows are returned by a dataset and then show the total number of rows as textbox.text and read-only so that the user can only see them but not change them?
so far I have this but it dosent return a number and says it cant find table 0:
tbRecordsFound.Text = ds.Tables(0).Rows.Count
Try something like this:
tbRecordsFound.Text = ds.Tables.Cast<DataTable>().Sum(x => x.Rows.Count).ToString()
You can also do it like this:
Dim recordCount as Integer = 0;
For Each table as Datatable in ds.Tables
recordCount += table.Rows.Count
tbRecordsFound.Text = recordCount.ToString()
tbRecordsFound.Text = ds.Tables(0).Rows.Count
The above code will work, however you need to give the table an identifier, such as:
tbRecordsFound.Text = ds.Tables("TableName").Rows.Count
This can be done via creating a DataAdapter and using the "Fill" function to give the table a name. Here is an example where "da" represents the DataAdapter:
da.Fill(ds, "TableName")
For i As Integer = 0 To yourdatagridviewName.Rows.Count() - 1 Step +1
i = +i
TextBox2.Text = i
Next

datagridview and empty table

DataGridView1.DataSource = ds.Tables("Orders")
If the query returns no results (empty dataset table) I see -1 in first column of the DataGridView in OrderID column. When I click on a grid columns header it decreases -2, -3 etc.
How to fix it?
How about:
If ds.Tables("Orders").Rows.Count = 0 Then
lblNoResults.Visible = True
DataGridView1.Visible = False
Else
lblNoResults.Visible = False
DataGridView1.DataSource = ds.Tables("Orders")
'Anything else you need to do
DataGridView1.Visible = True
End If
lblNoResults would be a label with text something like "No results found" that you would display instead of your DataGridView.
Basically, don't bind the datasource if there are no rows in it.
It might be that there are bugs in your other code causing your specific problem. If you want to show more of your code then it'll be easier to say what's going wrong.