| |

VerySource

 Forgot password?
 Register
Search
View: 848|Reply: 5

About datagrid data preservation (urgent)

[Copy link]

1

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 10:30:02
| Show all posts |Read mode
The button calls the following method: no error is reported, but the data does not change when re-retrieving
public static void UpdateDataset(DataSet dataSet, string tableName,string connstr)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string ls_sql = "select top 0 * from "+ tableName;
SqlDataAdapter da = new SqlDataAdapter(ls_sql,conn);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
ds.Clear();
da.Fill(ds,tableName);
ds = dataSet.Copy();
try
{
da.Update(ds,tableName);
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
conn.Close();
da.Dispose();
cb.Dispose();
ds.Dispose();
dataSet.AcceptChanges();
}
}
Reply

Use magic Report

1

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-11-11 10:45:01
| Show all posts
private void button3_Click(object sender, System.EventArgs e)
{
dscus.AcceptChanges();
JXC.publicdata.UpdateDataset(dscus,"customer",conntodatabase.dataconn);
}
This is the button event code as above: call publicdata.UpdateDataset method
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-11-11 11:00:02
| Show all posts
Follow up
Reply

Use magic Report

1

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-11-11 14:15:01
| Show all posts
After tracking, no problem was found. No matter it is added, it will not be saved after editing! The data has not changed, all have a primary key
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 16:15:01
| Show all posts
public int UpdateDataset(System.Data.DataTable qgf_DataTable, string selectCommand,System.Data.SqlClient.SqlCommand qgf_Insert)
{
using(SqlConnection qgf_SqlConnection=new SqlConnection())
{
qgf_SqlConnection.ConnectionString=this._strSQLString;
SqlCommand qgf_SqlCommand=new SqlCommand();
qgf_SqlCommand.Connection=qgf_SqlConnection;
qgf_SqlCommand.CommandType=CommandType.StoredProcedure;
qgf_SqlCommand.CommandText=selectCommand;

qgf_Insert.Connection=qgf_SqlConnection;
qgf_Insert.CommandType=CommandType.StoredProcedure;

SqlDataAdapter adapter = new SqlDataAdapter(qgf_SqlCommand);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);

adapter.InsertCommand=qgf_Insert;

adapter.UpdateCommand=cmdBuilder.GetUpdateCommand();
adapter.DeleteCommand=cmdBuilder.GetDeleteCommand();
int val=0;
try
{
val = adapter.Update(qgf_DataTable);
qgf_DataTable.AcceptChanges();
}
catch(System.Exception Ex)
{
val=2;
}
finally
{
adapter.Dispose();
cmdBuilder.Dispose();
qgf_SqlCommand.Dispose();
qgf_SqlConnection.Dispose();

}
return val;
}
}
Reply

Use magic Report

3

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-11-11 16:30:01
| Show all posts
Can you explain the code above, I don’t understand it too well, is it a function written by yourself? What are the parameters to be passed, thank you
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