第一次将数据网格保存到数据库感谢您的帮助。
我以这种方式填充dataGrid:
private void FillGrid1()
{
frmEditovat frm2 = new frmEditovat(this);
DataTable DT = null;
DataRow newRow;
int pTypNastaveniaID = 0;
string pNazov = "", pHodnota = "";
DataConnector_My dataConnector = new DataConnector_My(mDataRoot.ConnectCentrum.ConnectionString);
try
{
dataConnector.Init(mDataRoot.ConnectCentrum);
DT = dataConnector.Get_Nastavenia();
/* Odstranim zdroj pre Grid. Musi byt koli triedeniu gridu. */
dataGridView1.DataSource = null;
/* Smazanie Tabulky. */
mDTable1.Clear();
for (int row = 0; row < DT.Rows.Count; row++)
{
pTypNastaveniaID = 0; pNazov = ""; pHodnota = "";
if (DT.Rows[row]["TypNastaveniaID"] != DBNull.Value) pTypNastaveniaID = Convert.ToInt32(DT.Rows[row]["TypNastaveniaID"]);
if (DT.Rows[row]["Nazov"] != DBNull.Value) pNazov = DT.Rows[row]["Nazov"].ToString();
if (DT.Rows[row]["Hodnota"] != DBNull.Value) pHodnota = DT.Rows[row]["Hodnota"].ToString();
newRow = mDTable1.NewRow();
newRow["TypNastaveniaID"] = pTypNastaveniaID;
newRow["Nazov"] = pNazov;
newRow["Hodnota"] = pHodnota;
mDTable1.Rows.Add(newRow);
}
/* Datovy zdroj zpet. */
dataGridView1.DataSource = mDTable1;
Application.DoEvents();
}
catch (SqlException e)
{
MessageBox.Show(this.GetType() + ".FillGrid: " + Environment.NewLine + e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
DT.Dispose();
}
}
单击按钮中的操作后,我想将 datagriView1 保存到数据库:
private void btnSave_Click_1(object sender, EventArgs e)
或者一些具有类似代码的示例将不胜感激。