473,500 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagridview and database

6 New Member
Hey.. I have a form consisting of datagridview and two buttons of update and load all.. I have used fillby method to obtain data from database. The query seems to be working fine, except that the data is not shown in the gridview.
As in, for the qeury, if the returned rows are 2, it will show 3 rows in the gridview, but all empty.
Here is my code.. Please help me !!

Vb.net and Ms Access 2003

Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Data
  3. Imports System.Data.OleDb
  4. Imports System.EventArgs
  5. Imports System.Data.OleDb.OleDbConnection
  6. Imports System.Data.OleDb.OleDbCommand
  7.  
  8. Public Class Form1
  9.     Inherits System.Windows.Forms.Form
  10.  
  11.     Dim wrkdir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
  12.     Dim da As New OleDbDataAdapter
  13.     Dim ds As New DataSet
  14.     Dim bs As New BindingSource
  15.     Dim edit As Boolean
  16.     'Dim cnn As OleDbConnection
  17.  
  18.  
  19.     Dim cnn As New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
  20.  
  21.     'cnn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
  22.     'cnn.Open()
  23.  
  24.     Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
  25.  
  26.         If edit Then
  27.             da.Update(ds, "partno")
  28.             edit = False
  29.         End If
  30.  
  31.     End Sub
  32.  
  33.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  34.         'TODO: This line of code loads data into the 'HemDatabase1DataSet.partno' table. You can move, or remove it, as needed.
  35.         Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet.partno)
  36.  
  37.         dgv1.DataSource = bs
  38.  
  39.         'Dim cnn As New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
  40.         'cnn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
  41.         'cnn.Open()
  42.  
  43.     End Sub
  44.  
  45.     Private Sub button2_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
  46.  
  47.         ds.Tables.Clear()
  48.  
  49.         If tsText.Text <> "" Then
  50.  
  51.             Dim sql As String = "SELECT partno.partnum, partno.partname, partno.partdesc, partno.partqty " & _
  52.                                 "FROM(partno)" & _
  53.                                 "WHERE (((partno.type)='" & tsText.Text & "'));"
  54.  
  55.             Dim cmd As New OleDbCommand(sql, cnn)
  56.  
  57.             da.SelectCommand = cmd
  58.  
  59.             Dim cmdBuilder As New OleDbCommandBuilder(da)
  60.  
  61.             da.Fill(ds, "partno")
  62.             bs.DataSource = ds.Tables(0)
  63.  
  64.         Else
  65.  
  66.             Exit Sub
  67.  
  68.         End If
  69.     End Sub
  70.  
  71.     Private Sub button3_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles button3.Click
  72.  
  73.         ds.Tables.Clear()
  74.  
  75.         Dim sql As String = "SELECT * FROM partno;"
  76.         Dim cmd As New OleDbCommand(sql, cnn)
  77.  
  78.         da.SelectCommand = cmd
  79.  
  80.         Dim cmdbuilder As New OleDbCommandBuilder(da)
  81.         da.Fill(ds, "partno")
  82.         bs.DataSource = ds.Tables(0)
  83.  
  84.     End Sub
  85.  
  86.     Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
  87.         Try
  88.             Me.PartnoTableAdapter.FillBy(Me.HemDatabase1DataSet.partno, tsText.Text)
  89.         Catch ex As System.Exception
  90.             System.Windows.Forms.MessageBox.Show(ex.Message)
  91.         End Try
  92.  
  93.     End Sub
  94. End Class
  95.  
  96.  
Oct 7 '11 #1
0 1415

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

Similar topics

0
4085
by: T.Haugnes | last post by:
I've installed visual studio c# express, .net SDK 2.0, SQL Server Express, created a table in the SQL database and filled this with some data-rows. I dragged the database-table from Data...
0
9586
by: thomasp | last post by:
This is a two part question, 1) The code below should display a form with a datagridview and a few command buttons. This form should allow the user to make change to the records displayed in...
0
6908
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {...
0
2272
by: schoultzy | last post by:
Hello Everyone, I have been trying to figure this one out for two days now. I have created a DataGridView which is populated by an ObjectDataSource. My problem occurs when I attempt to use the...
2
15515
by: Steve Richter | last post by:
what is the best way to use DataGridView to view data from large database tables? Where the sql select statement might return millions of rows? string connectionString =...
2
2211
by: snowdog17 | last post by:
Hello, I am a student and I need help with my VB task. I am currently using VB 2005 Express and I am fairly new to it, although I have programed in Delphi before....
1
3353
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
1
2804
by: Andrus | last post by:
I have Winforms DataGridView whose DataSource Rids is Marc sample TableListCollection<TRowderived from BindingList. It is used to edit invoice rows. If user presses Revert button, my application...
3
5701
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
2
13919
BRawn
by: BRawn | last post by:
Hi guys, I'm struggling to copy rows from one DataGridView to another. This may sound redundant but it's necessary for my Orders project. I have 3 DataGridViews on one form. The first...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.