| |

VerySource

 Forgot password?
 Register
Search
View: 770|Reply: 7

SqlCommandBuilder issues

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-10 17:30:01
| Show all posts |Read mode
I found a lot of information about SqlCommandBuilder, but the above examples update the database through DataSet, and I use DataTable and DataView, can anyone give me an example?
My program is as follows:

 DataGird dg = new DataGird ();
 DataTable dt = new DataTable ();
 DataView dv = new DataView ();

 SqlConnection conn = new SqlConnection (Sqlstring ());
 SqlDataAdapter da = new SqlDataAdapter (Sqltxt, conn);

 try
 {
    conn.Open ();
    da.Fill (dt);
 }
 catch (Exception ex)
 {
    MessageBox.Show (ex.Message);
 }
 finally
 {
    conn.Close ();
 }
 dt.TableName = tableName;
 dv.Table = dt;
 dg.DataSource = dv;
Reply

Use magic Report

1

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 Hong Kong

Post time: 2020-4-5 15:15:02
| Show all posts
DataGird dg = new DataGird ();
 DataTable dt = new DataTable ();
 DataView dv = new DataView ();

 SqlConnection conn = new SqlConnection (Sqlstring ());
 SqlDataAdapter da = new SqlDataAdapter (Sqltxt, conn);

 try
 {
    conn.Open ();
    da.Fill (dt);
 }
 catch (Exception ex)
 {
    MessageBox.Show (ex.Message);
 }
 finally
 {
    conn.Close ();
 }

dv.Table = dt;
 dv.Table = dt;
 dg.DataSource = dv.Table;
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-4-5 18:15:01
| Show all posts
public bool DataUpdate (DataTable dt)
{
try
{
The
OleAdpt.Update (dt.Select (null, null, DataViewRowState.Added));
return true;
}
catch (Exception ex)
{
The
throw ex;
return false;
}
}
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-5 21:15:01
| Show all posts
OleDbCommandBuilder oleCB = new OleDbCommandBuilder (oda);

oda.UpdateCommand = oleCB.GetUpdateCommand ();

.....
oda.Update (tablename);
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-6 15:30:02
| Show all posts
What should be done to write back the modified database?
Reply

Use magic Report

0

Threads

23

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-4-6 16:00:01
| Show all posts
DataGird dg = new DataGird ();
 DataTable dt = new DataTable ();
 DataView dv = new DataView ();

 SqlConnection conn = new SqlConnection (Sqlstring ());
 SqlDataAdapter da = new SqlDataAdapter (Sqltxt, conn);
OleDbCommandBuilder oleCB = new OleDbCommandBuilder (da);

 try
 {
    conn.Open ();
    da.Fill (dt);
 }
 catch (Exception ex)
 {
    MessageBox.Show (ex.Message);
 }
 finally
 {
    conn.Close ();
 }

dv.Table = dt;
 dv.Table = dt;
 dg.DataSource = dv.Table;
............
da.Update (dt);
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-4-7 01:00:02
| Show all posts
The code I sent was to update the database with dt
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-7 01:15:02
| Show all posts
Thatwudi1982
If the code above is written as a function, if you say that, it is not ...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list