본문 바로가기

C#

C# OleDb Excel to DataGridView Update(Save)

string _strConn = "Provider = Microsoft.ACE.OLEDB.12.0;" +
	"Data Source=" + OpenFilePathName + ";" +
	"Extended Properties='Excel 12.0;HDR=NO'";
using (OleDbConnection _OleConn = new OleDbConnection(_strConn))
{
	_OleConn.Open();

	string _StrCmd = "UPDATE [Sheet1$] SET F6='" + txtGold.Text + "' WHERE F2='" + txtID.Text + "'";
	OleDbCommand _OleCmd = new OleDbCommand(_StrCmd, _OleConn);
	_OleCmd.ExecuteNonQuery();

	if (_OleConn.State == ConnectionState.Open)
	{
		_OleConn.Close();
	}
}