日期:2014-05-17  浏览次数:21157 次

c# 当传递具有新行的 DataRow 集合时,更新要求有效的 InsertCommand
本帖最后由 ygy597441072 于 2013-03-07 13:29:07 编辑
public void DataBaseInSertFromOperateDataSet(string DataTableName, string ValueOfFieldString)
        {
            
            if (this.OleDbCommandString != null && this.ConnectionString != null)
            {
                this._ConnectionString = ConnectionString;
                this._OleDbCommandString = OleDbCommandString;
                MyConnection = new OleDbConnection(_ConnectionString);
                MyDataAdapter = new OleDbDataAdapter(_OleDbCommandString, MyConnection);

                MyDataSet = new DataSet();
                MyDataAdapter.Fill(MyDataSet, DataTableName);
                
                MyDataTable = MyDataSet.Tables[DataTableName];
                string[] ColumnName = new string[MyDataTable.Columns.Count];
                int i = 0;
                foreach (DataColumn Dc in MyDataTable.Columns)
                {
                    ColumnName[i] = Dc.ColumnName;
                    i++;

                }
                string[] ValueOfField = ValueOfFieldString.Split(new char[] { ',' });
                if (ValueOfField.Length != ColumnName.Length)
                {
                    MessageBox.Show("您输入的字段个数与数据库不匹配");

                }
                else
                {