Save dataGridView to database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:x-small <span style="line-height:19px With a button I load a XML file into a dataGridView.<br/>
<span style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:x-small <span style="line-height:19px Then I want to save this data to an attached database.Unfortunately it won t work. This is what
I got so far.<br/>
<br/>
<strong style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:13px; line-height:19px Load XML: <br/>
<span style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:x-small <span style="line-height:19px code:
<table style="
<tbody>
<tr>
<td style="font:normal normal normal 12px/125% courier new,courier,monospace; vertical-align:top; color:#000000; white-space:nowrap; text-align:right; width:22px; background-color:#e6e4e1; padding:4px; margin:0px; border:1px solid #000000
<pre style="display:block; color:#000000; font:normal normal normal 12px/125% courier new,courier,monospace; white-space:pre; margin:0px 1
2
3
4
5
6
7
8
9
10
11
12
13
[/code]
</td>
<td style="font:normal normal normal 12px/125% courier new,courier,monospace; vertical-align:top; color:#000000; white-space:nowrap; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-right-width:1px; border-right-style:solid; border-right-color:#000000; padding:0px; margin:0px
<div style="width:629px; overflow-x:auto; overflow-y:hidden; padding-bottom:0px
<pre style="display:block; color:#000000; font:normal normal normal 12px/125% courier new,courier,monospace; white-space:pre; background-color:#fefefe; border-top-width:1px; border-top-style:solid; border-top-color:#000000; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#000000; padding:4px; margin:0px private void Openen_Click(object sender, EventArgs e)
{
DataSet bakker2 = new DataSet("Bestelling");

OpenFileDialog fd = new OpenFileDialog();
fd.ShowDialog();
label1.Text = fd.FileName;

bakker2.ReadXml(label1.Text = fd.FileName);
dataGridView1.DataSource = bakker2;
dataGridView1.DataMember = "Bestelling";
// dataGridView1.CaptionText = dataGridView1.DataMember;
}[/code]

</td>
</tr>
</tbody>
</table>
<br/>
<strong style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:13px; line-height:19px Save to database: <br/>
<span style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:x-small <span style="line-height:19px code:
<table style="
<tbody>
<tr>
<td style="font:normal normal normal 12px/125% courier new,courier,monospace; vertical-align:top; color:#000000; white-space:nowrap; text-align:right; width:22px; background-color:#e6e4e1; padding:4px; margin:0px; border:1px solid #000000
<pre style="display:block; color:#000000; font:normal normal normal 12px/125% courier new,courier,monospace; white-space:pre; margin:0px 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[/code]
</td>
<td style="font:normal normal normal 12px/125% courier new,courier,monospace; vertical-align:top; color:#000000; white-space:nowrap; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-right-width:1px; border-right-style:solid; border-right-color:#000000; padding:0px; margin:0px
<div style="width:629px; overflow-x:auto; overflow-y:hidden; padding-bottom:0px
<pre style="display:block; color:#000000; font:normal normal normal 12px/125% courier new,courier,monospace; white-space:pre; background-color:#fefefe; border-top-width:1px; border-top-style:solid; border-top-color:#000000; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#000000; padding:4px; margin:0px private void Save_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.bestellingBindingSource.EndEdit();
this.bestellingTableAdapter.Update(this.bakkerDataSet.Bestelling);

MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}
}[/code]

</td>
</tr>
</tbody>
</table>
<span style="font-family:arial,helvetica,liberation sans,dejavu sans condensed,sans-serif; font-size:13px; line-height:19px <br/>


View the full article
 
Back
Top