Displaying record from SQL Server in a grid

Reply

Join Date: May 2008
Posts: 23
Reputation: realone has a little shameless behaviour in the past 
Solved Threads: 0
realone realone is offline Offline
Newbie Poster

Displaying record from SQL Server in a grid

 
0
  #1
Aug 21st, 2009
Pls see my code.Nothing is displaying in the grid

  1. Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim connString As String = "Provider=SQLOLEDB;Data Source=MSALAMEEN;uid=sa;pwd=Sa1;Initial Catalog=Biometric"
  3. Dim myConnection As OleDbConnection = New OleDbConnection
  4. myConnection.ConnectionString = connString
  5. Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select ID from bdata", myConnection)
  6. Dim ds As DataSet = New DataSet
  7. Dim dc1 As DataColumn = New DataColumn
  8. 'da.Fill(ds)
  9. da.Fill(ds, "bdata")
  10. dc1 = ds.Tables("bdata").Columns("id")
  11. DataGridView1.DataSource = ds.DefaultViewManager
Last edited by John A; Aug 21st, 2009 at 6:33 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 249
Reputation: jbisono is an unknown quantity at this point 
Solved Threads: 35
jbisono's Avatar
jbisono jbisono is offline Offline
Posting Whiz in Training

Re: Displaying record from SQL Server in a grid

 
0
  #2
Aug 21st, 2009
add this at the end.
DataGridView1.DataBind()

regards
If your already resolved your issue, flag it as solved.
José Bisonó
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3,949
Reputation: adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future 
Solved Threads: 705
Moderator
adatapost adatapost is offline Offline
Senior Poster

Re: Displaying record from SQL Server in a grid

 
0
  #3
Aug 22nd, 2009
@jbisono: add this at the end. DataGridView1.DataBind()
No, It's not working. It is for ASP.NET.

  1. DataGridView1.DataSource = ds.Table("bdata")
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 249
Reputation: jbisono is an unknown quantity at this point 
Solved Threads: 35
jbisono's Avatar
jbisono jbisono is offline Offline
Posting Whiz in Training

Re: Displaying record from SQL Server in a grid

 
0
  #4
Aug 24th, 2009
Oops that is true adatapost my bad.
thanks for correcting me.
If your already resolved your issue, flag it as solved.
José Bisonó
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 150
Reputation: samir_ibrahim is on a distinguished road 
Solved Threads: 16
samir_ibrahim's Avatar
samir_ibrahim samir_ibrahim is offline Offline
Junior Poster

Re: Displaying record from SQL Server in a grid

 
1
  #5
Aug 24th, 2009
Originally Posted by realone View Post
Pls see my code.Nothing is displaying in the grid

  1. Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim connString As String = "Provider=SQLOLEDB;Data Source=MSALAMEEN;uid=sa;pwd=Sa1;Initial Catalog=Biometric"
  3. Dim myConnection As OleDbConnection = New OleDbConnection
  4. myConnection.ConnectionString = connString
  5. Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select ID from bdata", myConnection)
  6. Dim ds As DataSet = New DataSet
  7. Dim dc1 As DataColumn = New DataColumn
  8. 'da.Fill(ds)
  9. da.Fill(ds, "bdata")
  10. dc1 = ds.Tables("bdata").Columns("id")
  11. DataGridView1.DataSource = ds.DefaultViewManager
Try this,
After the last line add
DataGridView1.DataMember = "bdata"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 555 | Replies: 4
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC