35 Replies - 3010 Views - Last Post: 08 October 2011 - 02:59 AM
#16
Re: Datagridview and databse
Posted 07 October 2011 - 04:44 AM
#17
Re: Datagridview and databse
Posted 07 October 2011 - 06:12 AM
Now, the scenario is :
Update is not functioning..
FillBy tool strip is showing all the data, instead of the filtered data. It shows all the data in updated form ie. after updating newly added data as well, dont know how !!
Load All button is showing some filtered data instead of showing all data in database..
I m finally attaching current code for ur reference..
Imports System.Data
Imports System.Data.OleDb
Imports System.EventArgs
Imports System.Data.OleDb.OleDbConnection
Imports System.Data.OleDb.OleDbCommand
Public Class Form1
Inherits System.Windows.Forms.Form
Dim wrkdir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim bs As New BindingSource
Dim edit As Boolean
'Dim cnn As OleDbConnection
Dim cnn As New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
'cnn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
'cnn.Open()
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
'Dim change As DataSet = ds.GetChanges()
'Dim commandbuild As New OleDbCommandBuilder(da)
'If change IsNot Nothing Then
' da.Update(change)
'End If
dgv1.DataSource = bs
If edit Then
da.Update(ds, "partno")
edit = False
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'HemDatabase1DataSet.partno' table. You can move, or remove it, as needed.
Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet.partno)
dgv1.DataSource = Me.HemDatabase1DataSet.partno
bs.DataSource = ds.Tables(0)
'dgv1.DataMember = "partno"
'Dim cnn As New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
'cnn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
'cnn.Open()
End Sub
Private Sub button2_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
dgv1.DataSource = Me.HemDatabase1DataSet.partno
ds.Tables.Clear()
If tsText.Text <> "" Then
Dim sql As String = "SELECT partnum, partname, partdesc, partqty " & _
"FROM (partno) " & _
"WHERE type='" & tsText.Text & "';"
Dim cmd As New OleDbCommand(sql, cnn)
da = New OleDbDataAdapter(cmd)
'da.SelectCommand = cmd
'Dim cmdBuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
Else
Exit Sub
End If
End Sub
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles button3.Click
ds.Tables.Clear()
Dim sql As String = "SELECT * FROM partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
End Sub
Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
Try
Me.PartnoTableAdapter.FillBy(Me.HemDatabase1DataSet.partno, tsText.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Where :
update : button1
fillbytoolstrip : button2
loadall : button3
Thank u
#18
Re: Datagridview and databse
Posted 07 October 2011 - 08:02 AM
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles button3.Click 'and Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Clickyou confuse here and cause the problem
#19
Re: Datagridview and databse
Posted 07 October 2011 - 10:41 PM
Try
Me.PartnoTableAdapter.FillBy(Me.HemDatabase1DataSet.partno, tsText.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
ds.Tables.Clear()
Dim sql As String = "SELECT * FROM partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
Thank you so much for helping me till now !! For update is :
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
'Dim change As DataSet = ds.GetChanges()
'Dim commandbuild As New OleDbCommandBuilder(da)
'If change IsNot Nothing Then
' da.Update(change)
'End If
dgv1.DataSource = bs
If edit Then
da.Update(ds, "partno")
edit = False
End If
End Sub
#20
Re: Datagridview and databse
Posted 07 October 2011 - 11:03 PM
Quote
fillbytoolstrip : button2
loadall : button3
ds.Tables.Clear()
Dim sql As String = "SELECT * FROM partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
Or I get it wrong? Is the update one working?
This post has been edited by smohd: 07 October 2011 - 11:05 PM
#21
Re: Datagridview and databse
Posted 07 October 2011 - 11:10 PM
Loadall is button2
Fillby is button3
No... update is not working !!
Thanks..
This post has been edited by Ruchi22: 07 October 2011 - 11:34 PM
#22
Re: Datagridview and databse
Posted 07 October 2011 - 11:20 PM
So if button2 is to load by then the code which I removed should be in button3 and those posted above in button2.
Then post our updated code and put comment in each sub saying what that sub should do and what is doing now
This post has been edited by smohd: 07 October 2011 - 11:25 PM
#23
Re: Datagridview and databse
Posted 07 October 2011 - 11:33 PM
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
'Dim change As DataSet = ds.GetChanges()
'Dim commandbuild As New OleDbCommandBuilder(da)
'If change IsNot Nothing Then
' da.Update(change)
'End If
dgv1.DataSource = bs
If edit Then
da.Update(ds, "partno")
edit = False
End If
End Sub
Next is for loadall.. It should load all the data in database, even the updated ones.. Usually, a user may need to view all data after he/she is done with filtered data. It is for that.. However, this button shows only filtered data by type, that too excluding the updated/newly added data.
Private Sub button2_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet.partno)
dgv1.DataSource = Me.HemDatabase1DataSet.partno
ds.Tables.Clear()
If tsText.Text <> "" Then
Dim sql As String = "SELECT partnum, partname, partdesc, partqty " & _
"FROM (partno) " & _
"WHERE type='" & tsText.Text & "';"
Dim cmd As New OleDbCommand(sql, cnn)
da = New OleDbDataAdapter(cmd)
'da.SelectCommand = cmd
'Dim cmdBuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
Else
Exit Sub
End If
End Sub
Final is the toolstripbutton.. Used to display data that are filtered by type. This does show data filtered by type but does not include the update/newly added data.
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles button3.Click
Try
Me.PartnoTableAdapter.FillBy(Me.HemDatabase1DataSet.partno, tsText.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
ds.Tables.Clear()
Dim sql As String = "SELECT * FROM partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
End Sub
#24
Re: Datagridview and databse
Posted 07 October 2011 - 11:45 PM
Sorry for the mess up in post 17..
This post has been edited by Ruchi22: 07 October 2011 - 11:47 PM
#25
Re: Datagridview and databse
Posted 08 October 2011 - 12:10 AM
By starting, your code should be like this for button2( you missed the last lline which tells the data grid view where to take data now)
Private Sub button2_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
ds.Tables.Clear()
Dim sql As String = "SELECT * FROM partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
dgv1.DataSource = bs 'this line was missing
End Sub
Ok try it and I am looking for others
#26
Re: Datagridview and databse
Posted 08 October 2011 - 12:37 AM
Thank you.. Awaiting your reply for other two !!
Thank you so much, again !!
#27
Re: Datagridview and databse
Posted 08 October 2011 - 12:53 AM
ds.Tables.Clear()
If tsText.Text <> "" Then
Dim sql As String = "SELECT * FROM (partno) WHERE type='" & tsText.Text & "';"
Dim cmd As New OleDbCommand(sql, cnn)
da = New OleDbDataAdapter(cmd)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
dgv1.DataSource = bs
Glad this will work too, test it and give back feeds if working or not.
#28
Re: Datagridview and databse
Posted 08 October 2011 - 01:10 AM
This button also worked.. Now finally the last one.. update remains..
Thank you so much for your help !!
#29
Re: Datagridview and databse
Posted 08 October 2011 - 01:14 AM
Dim change As DataSet = HemDatabase1DataSet.GetChanges()
Dim commandbuild As New OleDbCommandBuilder(da)
da.SelectCommand = New OleDbCommand("SELECT * FROM partno", cnn) 'this line was missing
If change IsNot Nothing Then
da.Update(change, "partno")
End If
This post has been edited by smohd: 08 October 2011 - 01:15 AM
#30
Re: Datagridview and databse
Posted 08 October 2011 - 01:19 AM
|
|

New Topic/Question
Reply





MultiQuote


|