|
-
May 12th, 2009, 10:11 PM
#1
Thread Starter
Frenzied Member
datagrid
Hi,
I have a datagrid view, textboes and a dataset.
I would like the data i have in the datagridview and textboxes to be saved in my datasset.
Can you please show me how i can do that
Thanks
-
May 12th, 2009, 10:17 PM
#2
Re: datagrid
Just bind your DataTable to you controls and you're done. Any changes you make to one will be automatically pushed to the other:
vb.net Code:
Me.BindingSource1.DataSource = myDataSet Me.BindingSource1.DataMember = "MyTable" Me.DataGridView1.DataSource = Me.BindingSource1 Me.TextBox1.DataBindings.Add("Text", Me.BindingSource1, "MyColumn")
-
May 12th, 2009, 10:25 PM
#3
Thread Starter
Frenzied Member
Re: datagrid
Hi,
Thanks for quick reply. Can you pleas ecplain me in detail the code here
#
Me.BindingSource1.DataSource = myDataSet
#
Me.BindingSource1.DataMember = "MyTable"
Thanks
-
May 12th, 2009, 10:28 PM
#4
Re: datagrid
The DataSource is the source of the data. The DataMember is the member of that data source that contains the data you want to bind. I suggest that you open your MSDN Library and read the documentation for the BindingSource class and fro those properties in particular. I recommend that you do that every time you have a question, then post if you can't find what you need or don't understand what you find. You don't need us to provide information that you already have.
-
May 13th, 2009, 09:25 AM
#5
Thread Starter
Frenzied Member
Re: datagrid
ok, well i made my code like this, i was able to show that on the boes in the report, but not the datagrid view.
vb Code:
Dim dt As DataTable Dim dr As DataRow Me.BindingSource1.DataMember = "dt" Me.BindingSource1.DataSource = DataSet2 dt = New DataTable("tableReport") dt.Columns.Add(New DataColumn("nom")) dt.Columns.Add(New DataColumn("prenom")) dt.Columns.Add(New DataColumn("datedenaissance")) dr = dt.NewRow dr("nom") = loginid.Text dr("prenom") = ComboBox1.Text dr("datedenaissance") = TextBox2.Text dt.Rows.Add(dr) Dim report1 As New rptreport report1.SetDataSource(dt) Form1.CrystalReportViewer1.ReportSource = report1 Form1.Show()
Me.BindingSource1.DataSource = DataSet2
here i get an error 'DataSet2' is a type and cannot be used as an expression.
In the data set i have a datatable named dt and three column.
What could be the problem?
thx
-
May 13th, 2009, 09:36 AM
#6
Re: datagrid
The problem could be that you have to bind an instance of the DataSet2 class, not the DataSet2 class itself.
-
May 13th, 2009, 09:41 AM
#7
Thread Starter
Frenzied Member
Re: datagrid
ok, i did it as u said now no code error, but i don't see my datagrid data in my dataset or report, what else do i have to make to make it appear in my report or dataset?
Thanks
-
May 13th, 2009, 09:51 AM
#8
Re: datagrid
Have you retrieved any data from the database? It doesn't happen on its own. You have to provide code to get the data.
-
May 13th, 2009, 10:13 AM
#9
Thread Starter
Frenzied Member
Re: datagrid
Yes i filled the datagrid then put the code u gave me. I think the code u gave is to retrive data from dataset to datagrid. i want from datagrid to dataset
thx
-
May 13th, 2009, 11:05 AM
#10
Thread Starter
Frenzied Member
Re: datagrid
i tried to write the code like this
vb Code:
Me.BindingSource1.DataSource = dataGridEleveMoyen.DataSource DataSet3 = BindingSource1.DataSource
but i'm getting this error Unable to cast object of type 'System.Data.DataView' to type 'EleveMoyen.DataSet3'.
-
May 13th, 2009, 07:40 PM
#11
Re: datagrid
You're doing this all wrong. You don't have to do anything to get the data from the grid to the DataSet. That's the whole point of data-binding. You populate a DataTable and bind that to the grid. Now, any changes you make to the grid will automatically affect the DataTable because they are bound. So:
1. Populate a DataTable.
2. Bind the table to a BindingSource.
3. Bind the source to the grid.
That's it. That is all you have to do. The user makes their edits in the grid and then you save the changes in the DataTable back to the database. That is ALL you need to do.
-
May 13th, 2009, 09:09 PM
#12
Thread Starter
Frenzied Member
Re: datagrid
Hi,
i guess its here where i am blocked.
2. Bind the table to a BindingSource.
3. Bind the source to the grid.
how do i do that?
thx
-
May 13th, 2009, 09:20 PM
#13
Re: datagrid
Go back and read post #2. An alternative to this:
vb.net Code:
Me.BindingSource1.DataSource = myDataSet Me.BindingSource1.DataMember = "MyTable"
is this:
vb.net Code:
Me.BindingSource1.DataSource = myDataSet.Tables("MyTable")
or, if you're using a typed DataSet, this:
vb.net Code:
Me.BindingSource1.DataSource = myDataSet.MyTable
-
May 13th, 2009, 09:51 PM
#14
Thread Starter
Frenzied Member
Re: datagrid
Hi,
I did it like that but nothing appearing in the report.
vb Code:
Dim dt As DataTable Dim dr As DataRow Me.BindingSource1.DataSource = DataSet3 Me.BindingSource1.DataMember = "moyenn" Me.BindingSource1.DataSource = DataSet3.Tables("moyenn") ' Me.BindingSource1.DataMember = "EleveMoyen" ' DataSet3 = dsResult.Tables("EleveMoyen") dt = New DataTable("tableReport") dt.Columns.Add(New DataColumn("nom")) dt.Columns.Add(New DataColumn("prenom")) dt.Columns.Add(New DataColumn("datedenaissance")) dr = dt.NewRow dr("nom") = loginid.Text dr("prenom") = ComboBox1.Text dr("datedenaissance") = TextBox2.Text dt.Rows.Add(dr) Dim report1 As New rptreport report1.SetDataSource(dt) Form1.CrystalReportViewer1.ReportSource = report1 Form1.Show()
thanks
-
May 13th, 2009, 09:56 PM
#15
Re: datagrid
1. Why are you binding the same data to the BindingSource twice?
2. Why are you binding the data to the BindingSource at all because the BindingSource isn't then used again in that code.
3. Why are you creating a new DataTable to use for the report when you already have a DataTable in the DataSet?
You seem to have parts of two completely unrelated sections of code there so i don't know what's supposed to be happening. Also, I can't really help you with CR as I don't use it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|