| |

VerySource

 Forgot password?
 Register
Search
View: 1211|Reply: 10

Can't add data to the database, why?

[Copy link]

3

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 Invalid IP Address

Post time: 2020-2-5 09:00:01
| Show all posts |Read mode
Note that the managerDataSet and jYDJLTableAdapter are generated after the system performs data binding, so there is no need to manually give the insertcommand. In the breakpoint, I can find that the managerDataSet has successfully added new rows, but the tableadapter does not use the new rows. The insert method is added to the database. Why is this so?
DataRow itemrow = managerDataSet.JYDJL.NewRow ();
                    itemrow ["Transaction time"] = dateTimePicker1.Value;
                    itemrow ["Transaction Type"] = comboBox1.Text.ToString (). Trim ();
                    itemrow ["Transaction Kind"] = comboBox2.Text.ToString (). Trim ();
                    itemrow ["Game"] = comboBox3.Text.ToString (). Trim ();
                    itemrow ["District service"] = textBox4.Text.ToString (). Trim ();
                    itemrow ["Account"] = textBox5.Text.ToString (). Trim ();
                    itemrow ["PIN"] = textBox6.Text.ToString (). Trim ();
                    itemrow ["Person Name"] = textBox7.Text.ToString (). Trim ();
                    itemrow ["Payment Method"] = comboBox4.Text.ToString (). Trim ();
                    itemrow ["Transaction Amount"] = d;
                    itemrow ["Payment Status"] = comboBox5.Text.ToString (). Trim ();
                    itemrow ["generation status"] = comboBox6.Text.ToString (). Trim ();
                    itemrow ["Trader"] = textBox9.Text.ToString (). Trim ();
                    itemrow ["Trading Platform"] = comboBox7.Text.ToString (). Trim ();
                    itemrow ["Communication Software"] = comboBox8.Text.ToString (). Trim ();
                    itemrow ["Communication Software ID"] = textBox10.Text.ToString (). Trim ();
                    itemrow ["Phone"] = textBox11.Text.ToString (). Trim ();
                    if (textBox12.Text.Trim ()! = "")
                    {
                        itemrow ["Task Time"] = dateTimePicker2.Value;
                    }
                    if (textBox13.Text.Trim ()! = "")
                    {
                        itemrow ["Completion time"] = dateTimePicker3.Value;
                    }
                    itemrow ["Detailed Description"] = richTextBox1.Text.ToString (). Trim ();
                    managerDataSet.JYDJL.Rows.Add (itemrow);
                    jYDJLBindingSource.EndEdit ();
                    try
                    {
                        jYDJLTableAdapter.Update (managerDataSet.JYDJL);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show ("Add failed! Reason for failure:" + ex.Message, "Hint", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-3-23 16:45:01
| Show all posts
managerDataSet.AcceptChanges ();
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 United States

Post time: 2020-3-23 23:45:01
| Show all posts
Have you used CommandBuilder?
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 Czech Republic

Post time: 2020-3-24 09:45:01
| Show all posts
See MSDN for usage:

for examele:
public DataSet CreateCmdsAndUpdate (DataSet dataSet, string connectionString,
    string queryString)
{
    using (OleDbConnection connection = new OleDbConnection (connectionString))
    {
        OleDbDataAdapter adapter = new OleDbDataAdapter ();
        adapter.SelectCommand = new OleDbCommand (queryString, connection);
        OleDbCommandBuilder builder = new OleDbCommandBuilder (adapter);

        connection.Open ();

        DataSet customers = new DataSet ();
        adapter.Fill (customers);

        // code to modify data in dataset here
        // Add your changes to the table here:

        adapter.Update (customers);

        return customers;
    }
}
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-3-24 11:30:02
| Show all posts
Yes, I didn't look carefully just now

If you do not use the CommandBuilder to automatically generate SQL statements, you need to manually specify InsertCommand, selectCommand, and UpdateCommand.
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-25 19:15:02
| Show all posts
Need to use CommandBuilder to automatically generate SQL statements
Reply

Use magic Report

3

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-26 16:00:01
| Show all posts
This tableadapter is generated by the system and already has an insertcommand. Do I still need to specify it manually?
managerDataSet.AcceptChanges () is also added to the middle, and the result is still useless.
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-3-27 21:30:01
| Show all posts
Automatically generated by the system?

I still feel that my writing is relatively cool, at least I can control it, and it is easy to find if something goes wrong.
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 Unknown

Post time: 2020-3-29 15:30:01
| Show all posts
When you update, you can specify it and try again.
Reply

Use magic Report

3

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-31 09:15:02
| Show all posts
I used tableadapter above, I don't know what is the difference with da.update. Tableadapter does not seem to be able to perform commandbuilder. How to write insertcommand in this case?
In addition,psycholmu, what do you mean by re-designation?
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