资源简介

C#中DataGridView修改后直接保存到数据库实例程序,绝对可用,内附源码,有注释 主要代码: //单元格编辑结束后触发 private void dataGridView1_CellEndEdit_1(object sender, DataGridViewCellEventArgs e) { try { string rowid = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); string cellhead = dataGridView1.Columns[e.ColumnIndex].DataPropertyName; string cellvalue = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (cellhead == "domain") { cellhead = "[domain]"; } else { } if (cellvalue == "True" && cellhead == "passed") { cellvalue = "1"; } else { if (cellhead == "passed") { cellvalue = "0"; } else { } } string sqlcmd = "update domain_info set " + cellhead + "='" + cellvalue + "' where id=" + rowid; if (dbo.DBcmd(sqlcmd)) { resultshow.Text = " 编辑成功"; } else { resultshow.Text = " 编辑失败"; } } catch { MessageBox.Show("异常", "错误"); } }

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;


namespace WebSiteTest
{
    class DBOpera
    {


        public bool DBcmd (string sqlcmd)
        {
            try
            {
                OleDbConnection conn = new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=“ + Application.StartupPath + @“/domain.mdb“);
               
                    conn.Open();
                    OleDbCommand cmd = new OleDbCommand(sqlcmd conn);
                        int r = cmd.ExecuteNonQuery();

                        conn.Close();
                        conn.Dispose();
                        if (r > 0)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
               
               
               
                
            }
            catch
            {
                return false;
            }
        }


    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        619  2012-10-20 17:06  WebSiteTest\app.config

     文件      20480  2012-10-22 13:42  WebSiteTest\bin\Debug\Database.sdf

     文件     221184  2012-10-23 09:13  WebSiteTest\bin\Debug\domain.mdb

     文件      72704  2012-10-23 09:12  WebSiteTest\bin\Debug\WebSiteTest.exe

     文件        619  2012-10-20 17:06  WebSiteTest\bin\Debug\WebSiteTest.exe.config

     文件     110080  2012-10-23 09:12  WebSiteTest\bin\Debug\WebSiteTest.pdb

     文件      11600  2012-10-23 10:11  WebSiteTest\bin\Debug\WebSiteTest.vshost.exe

     文件        619  2012-10-20 17:06  WebSiteTest\bin\Debug\WebSiteTest.vshost.exe.config

     文件        490  2010-03-17 22:39  WebSiteTest\bin\Debug\WebSiteTest.vshost.exe.manifest

     文件      20480  2012-10-22 13:42  WebSiteTest\Database.sdf

     文件       1156  2012-10-22 13:04  WebSiteTest\DBOpera.cs

     文件     221184  2012-10-22 13:43  WebSiteTest\domain.mdb

     文件     150046  2012-10-22 13:43  WebSiteTest\domainDataSet.Designer.cs

     文件          3  2012-10-22 13:43  WebSiteTest\domainDataSet.xsc

     文件      38574  2012-10-22 13:43  WebSiteTest\domainDataSet.xsd

     文件          3  2012-10-22 13:43  WebSiteTest\domainDataSet.xss

     文件       5483  2012-10-23 09:12  WebSiteTest\Form1.cs

     文件      24790  2012-10-23 09:12  WebSiteTest\Form1.Designer.cs

     文件      11197  2012-10-23 09:12  WebSiteTest\Form1.resx

     文件      15218  2012-10-22 18:49  WebSiteTest\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6707  2012-10-23 09:12  WebSiteTest\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        270  2012-10-23 09:12  WebSiteTest\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        520  2012-10-23 09:12  WebSiteTest\obj\x86\Debug\GenerateResource.write.1.tlog

     文件      11969  2012-10-20 17:06  WebSiteTest\obj\x86\Debug\ResolveAssemblyReference.cache

     文件       9216  2012-10-20 16:55  WebSiteTest\obj\x86\Debug\TempPE\Database1DataSet.Designer.cs.dll

     文件      53248  2012-10-22 13:43  WebSiteTest\obj\x86\Debug\TempPE\domainDataSet.Designer.cs.dll

     文件        791  2012-10-23 10:11  WebSiteTest\obj\x86\Debug\WebSiteTest.csproj.FileListAbsolute.txt

     文件      72704  2012-10-23 09:12  WebSiteTest\obj\x86\Debug\WebSiteTest.exe

     文件       3146  2012-10-23 09:12  WebSiteTest\obj\x86\Debug\WebSiteTest.Main.resources

     文件     110080  2012-10-23 09:12  WebSiteTest\obj\x86\Debug\WebSiteTest.pdb

............此处省略21个文件信息

评论

共有 条评论