1

ウィザードを使用して切断されたデータ セット プロジェクトを作成していますが、テーブルからデータを更新および削除することはできますが、新しいデータ行を挿入することはできず、「成功」というメッセージ ボックスが表示されます !!!!

namespace Disconnected_Database_by_Wizard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlConnection myConnection = new SqlConnection();

        SqlDataAdapter myAdapter = null;

        private void Form1_Load(object sender, EventArgs e)
        {
            myConnection.ConnectionString = "Server=CompileMe;Database=MyDataBase;Integrated Security = True";
            myAdapter = new SqlDataAdapter("Select * from MyList", myConnection);
            myConnection.Open();
            myAdapter.Fill(dataSet1,"MyList");
            SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);

            myAdapter.InsertCommand = myCommandBuilder.GetInsertCommand();
            myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
            myAdapter.InsertCommand = myCommandBuilder.GetDeleteCommand();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                myAdapter.Update(dataSet1 ,"Mylist");
                MessageBox.Show("Success");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                myConnection.Close();

            }

        }
    }
}

前もって感謝します :)

4

1 に答える 1