1.如果列名为数据库的关键字则自动加上中括号“[]” 例如[level]
2.如果列名中带有特殊符号。[date(a)]
数据存储的过程:
1.在添加数据的时候:要带有中括号,有必要在添加参数的时候不要带特殊符号@Akv而不是@Akv(shixiao)(changwen)
SqlConnection connection = this.getConnection(); adapter = new SqlDataAdapter("select *from specification", connection); SqlCommand InsertCommand = new SqlCommand(); InsertCommand.Connection = connection; InsertCommand.CommandText = "insert into specification (Specification_ID,[Akvt(℃)],[Akv(shixiao)(changwen)],[Akumin(J)])" //,[Akvt(℃)],[Akv(shixiao)(changwen)],[Akumin(J)] + "values (@Specification_ID,@Akvt,@Akv,@Akumin)";//,@Akvt(℃),@Akv(shixiao)(changwen),@Akumin(J)
2.在传递参数的时候,列名不要加中括号,因为显示的数据没有中括号。
InsertCommand.Parameters.Add("@Specification_ID", SqlDbType.BigInt, 8, "Specification_ID"); InsertCommand.Parameters.Add("@Akvt", SqlDbType.NVarChar, 50, "Akvt(℃)"); InsertCommand.Parameters.Add("@Akv", SqlDbType.NVarChar, 50, "Akv(shixiao)(changwen)"); InsertCommand.Parameters.Add("@Akumin", SqlDbType.NVarChar, 50, "Akumin(J)"); adapter.InsertCommand = InsertCommand;