表 Student  属性 studentID name classID
表 Class    属性 ClassID className
我想在DataGridView中显示 StudentID name className
所以,将BindingSource绑定到Student_View (studentID, name, className)上,并将数据集保持在dataSet中
现在我要向Student表中插入新的数据
  public bool InsertSingleTableRecord(ref DataSet ds,string tableName,string tableKeyName,out string errMessage)
    {
        errMessage = "";
        return SqlHelper.InsertSingleTableRecord(ref ds, tableName, tableKeyName, ref errMessage);
    }
就会出现问题,该怎么解决???

解决方案 »

  1.   


    的确这样做的
     DataSet ds = ((DataSet)this.bgSource.DataSource).Clone();
                //DataSet ds = new DataSet();
                string errMessage;
                DataRowView drv = (DataRowView)this.bgSource[this.bgSource.Position];
                DataRow dr = ds.Tables["Student"].NewRow();
                for (int i = 0; i < ds.Tables["Student"].Columns.Count; i++)
                {
                    switch (ds.Tables["Student"].Columns[i].ColumnName)
                    {
                        case "Name":
                            {
                                if ((drv[i] == DBNull.Value) || (drv[i].ToString() == ""))
                                {
                                    MessageBox.Show("请输入名称!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    this.txtName.Focus();
                                    return false;
                                }
                                break;
                            }
                        default:
                            break;
                    }
                    if (drv[i] == DBNull.Value)
                    {
                        drv[i] = FdaGloble.SetDefaultValue(ds.Tables["Student"].Columns[i].DataType);
                    }
                    dr[i] = drv[i];
                }
                ds.Tables["Student"].Rows.Add(dr);现在的问题在于:BindingSource绑定的是试图,而我想操作的却是表