Thread View: borland.public.delphi.database.ado-net
2 messages
2 total messages
Started by Peter Jones
Fri, 08 Apr 2005 21:02
How to post the data in DBGrid into a database?
Author: Peter Jones
Date: Fri, 08 Apr 2005 21:02
Date: Fri, 08 Apr 2005 21:02
41 lines
1872 bytes
1872 bytes
Hi,
I use an Excel worksheet as a data source:
------------------------
CertNo Name
1 Peter
2 Jones
------------------------
Then, I do the following to modify the data. In fact, the
DBGrid shows the changes, and I also update the OleDBAdapter.
But when I check the excel worksheet, why isn't anything
changed?
------------------------------
string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Manuel\\DealSummary.xls;Extended properties=Excel 8.0;";
OleDbConnection Conn1 = new OleDbConnection(sConn);
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [Sheet1$]",Conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1,"Deal");
foreach (DataRow cRow in ds1.Tables["Deal"].Rows)
{
if (((string) cRow["CertNo"]) == "1")
{
cRow.BeginEdit();
cRow["Name"] = "Changed";
cRow.EndEdit();
cRow.AcceptChanges();
break;
}
}
da1.Update(ds1,"Deal");
dataGrid1.DataSource = ds1;
dataGrid1.DataMember = "Deal";
dataGrid1.DataBind();
------------------------------
Any suggestions? Thanks in advance.
Peter
Please ignore this thread, since I post it somewhere else!
Author: Peter Jones
Date: Sun, 10 Apr 2005 05:24
Date: Sun, 10 Apr 2005 05:24
43 lines
2090 bytes
2090 bytes
"Peter Jones" <peter@hotmail.com> wrote:
>
>Hi,
>
>I use an Excel worksheet as a data source:
>------------------------
>CertNo Name
>1 Peter
>2 Jones
>------------------------
>
>Then, I do the following to modify the data. In fact, the
>DBGrid shows the changes, and I also update the OleDBAdapter.
>But when I check the excel worksheet, why isn't anything
>changed?
>------------------------------
>string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Manuel\\DealSummary.xls;Extended properties=Excel 8.0;";
>OleDbConnection Conn1 = new OleDbConnection(sConn);
>OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [Sheet1$]",Conn1);
>
>DataSet ds1 = new DataSet();
>da1.Fill(ds1,"Deal");
>foreach (DataRow cRow in ds1.Tables["Deal"].Rows)
>{
> if (((string) cRow["CertNo"]) == "1")
> {
> cRow.BeginEdit();
> cRow["Name"] = "Changed";
> cRow.EndEdit();
> cRow.AcceptChanges();
> break;
> }
>}
>da1.Update(ds1,"Deal");
>
>dataGrid1.DataSource = ds1;
>dataGrid1.DataMember = "Deal";
>dataGrid1.DataBind();
>------------------------------
>
>Any suggestions? Thanks in advance.
>Peter
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads