你好,下面段代码在 “列4” 中输入 “0001” 成功存入 SQL 数据库 Test 表中,字段类型为 nvarchar(50):
注意:
1. 在进行数据存储时,应该指定存储数据类型为 ,DbType.String。
2. dr["列2"] = "0001";如果不以双引号形式赋值 value 将为 “1”。无法进行转化。存储方式见“ FpSpread1_UpdateCommand”。
- protected void Page_Load(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("列1");
- dt.Columns.Add("列2");
- dt.Columns.Add("列3");
- dt.Columns.Add("列4");
- DataRow dr = dt.NewRow();
- dr["列1"] = 11.000;
- dr["列2"] = "0001";
- dr["列3"] = 3;
- dt.Rows.Add(dr);
- this.FpSpread1.ActiveSheetView.DataAutoCellTypes = false;
- FpSpread1.DataSource = dt;
- FpSpread1.DataBind();
- FpSpread1.ActiveSheetView.ColumnHeader.RowCount = 2;
- DoubleCellType db = new DoubleCellType();
- db.DecimalDigits = 3;
- db.FixedPoint = true;
- db.ErrorMessage = "err message";
- TextCellType tc = new TextCellType();
- tc.AllowWrap = true;
- FpSpread1.ActiveSheetView.Cells[0, 0].CellType = db;
- FpSpread1.ActiveSheetView.Cells[0, 1].CellType = tc;
- FpSpread1.ActiveSheetView.Cells[0, 2].CellType = db;
- FpSpread1.ActiveSheetView.Cells[0, 3].CellType = tc;
- }
- protected void FpSpread1_UpdateCommand(object sender, SpreadCommandEventArgs e)
- {
- SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
- SqlDataSource1.InsertCommand = "INSERT INTO [test]([test]) VALUES(@insertpara)";
- SqlDataSource1.InsertParameters.Add(new Parameter("insertpara",DbType.String,e.EditValues[3].ToString()));
- SqlDataSource1.Insert();
- }
复制代码 |