By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Populating Datagridview

P: 22
Good day to all of you, i would like to ask how can i fix my code,
I have a strong typed dataset and table and filled by sql commmand, but when i test it. the rows on my datagrid had empty thanks in advance


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.         conn = GetConnect()
  4.         Dim sda As New SqlDataAdapter
  5.         Dim dset As New DataSet3
  6.         Dim qury As String = "SELECT F_Article_No, Article_Color, Article_Size PO_Qty, Unit_Selling_Price, Gross_Unit_Price, Net_Unit_Price FROM Tbl_PO_Item WHERE F_PO_No ='" & lbl_Po.Text & "'"
  7.  
  8.  
  9.  
  10.         sda.SelectCommand = New SqlCommand
  11.         sda.SelectCommand.Connection = conn
  12.         sda.SelectCommand.CommandText = qury
  13.  
  14.  
  15.         Try
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.             Dim dt As DataTable = dset._Sales_tbl
  25.             sda.Fill(dt)
  26.  
  27.  
  28.  
  29.             If Form4.grid_selected_item.Rows.Count < 1 Then
  30.                 Form4.grid_selected_item.Columns.Clear()
  31.  
  32.             End If
  33.             Form4.grid_selected_item.DataSource = dt
  34.  
  35.  
  36.  
  37.  
  38.         Catch ex As Exception
  39.             MessageBox.Show(ex.Message, "Something Went Wrong", MessageBoxButtons.OK, MessageBoxIcon.Error)
  40.         End Try
Apr 10 '14 #1
Share this Question
Share on Google+
3 Replies


100+
P: 294
What is conn? Are you even opening your connection to the database? I expected to see something like:
Expand|Select|Wrap|Line Numbers
  1. Dim conn As New YourDBTypeConnection(connStrings.ConnectionStrings("DBName").ConnectionString)


Why are you declaring a DataSet and a DataTable? You could use the first index of a DataSet as the DataTable.

Example:

Expand|Select|Wrap|Line Numbers
  1. DataGridView1.DataSource = dset.tables(0)
There are a lot of unknowns in your question, almost to the point where I am literally just assuming things. We are all guilty of this at times. Just remember, I don't know what GetConnect() means, nor do I know anything else about your project outside of what you posted here.

Hope this helps.
Apr 10 '14 #2

P: 22
Thank for response sir, "conn" is a variable declared at my module,to lessen my code(conn)
Expand|Select|Wrap|Line Numbers
  1.  conn = New SqlConnection("Data Source=192.168.14.40;Initial Catalog=Northwind;User ID=sms;Password=passw0rd")
, And about the Dataset, like what i said i create a strong typed dataset "DataSet3.xsd" , and i think it's work because all data that i need is show on my datagrid but they create they own column , the only problem of mine now is how can i put those data in their respective column,
Apr 11 '14 #3

P: 22
This regard this topic, i already solve my problem, instead of typed dataset i use untyped,
Apr 11 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.