-1
最後の4時間私のことを掴んでいる問題です。私のデータセットは変更を取得しますが、データベースはdoesntです。ただ、「グローバル」VARとして周りにありC#データベースがデータセットから更新されていません。 SQLCommandBuilder
スタッフ:
DatabaseConnection objConnect;
string conString;
DataSet ds;
int MaxRows;
マイフォームの負荷は、DB接続を初期化します
objConnect = new DatabaseConnection();
conString = Properties.Settings.Default.memoDbConnectionString;
objConnect.connection_string = conString;
私は私のデータセットを変更し、私を呼び出して、このボタンを持っていますデータベースの更新。私はDatabaseConnectionクラスで使用
private void button5_Click(object sender, EventArgs e)
{
//
objConnect.Sql = Properties.Settings.Default.userSQL;
ds = objConnect.GetConnection;
MaxRows = ds.Tables[0].Rows.Count;
for (int i = 0; i < MaxRows; i++)
{
DataRow dRow = ds.Tables[0].Rows[i];
if (nick == dRow.ItemArray[0].ToString())
if (textBox4.Text == textBox5.Text)
if (textBox3.Text == dRow.ItemArray[1].ToString())
{
ds.Tables[0].Rows[i][1] = textBox5.Text;
//this is the interesting bit
DataSet changes = ds.GetChanges();
objConnect.UpdateDatabase(changes);
//-----
MessageBox.Show(nick);
MessageBox.Show(dRow[1].ToString());
break;
}
else MessageBox.Show("Old password is wrong.");
else MessageBox.Show("Pass confirmation does not correspond.");
}
}
機能は:
public void UpdateDatabase(System.Data.DataSet ds)
{
System.Data.DataSet changes = ds.GetChanges();
System.Data.SqlClient.SqlCommandBuilder cb = new System.Data.SqlClient.SqlCommandBuilder(da_1);
//stuff thats suppsed to help
da_1.UpdateCommand = cb.GetUpdateCommand();
//----
da_1.Update(ds.Tables[0]);
ds.AcceptChanges();
}
da_1は、私は関数の外で宣言しますが、この1つだけ前に、関数の中にそれを属性SqlDataAdapterオブジェクトです。
私はちょうど1つのデータベースから読み取り、何らかの理由で別のデータベースに書き込むことがわかりました.my接続文字列は次のとおりです:Visual Studio 2015 \ Projects \ memo \ memo \ Resources \ memoDb.mdf –
ソリューションエクスプローラで、無視され、実際にはパスにあるものです。 –