using System;using System.Data;using System.Data.SqlClient;using System.Text;/// <summary>///BBSManager 的摘要說(shuō)明/// </summary>public class BBSManager{public BBSManager(){}/// <summary>///添加論壇的類(lèi)別/// </summary>/// <param name="name">類(lèi)別名稱(chēng)</param>/// <param name="des">類(lèi)別描述信息</param>///<returns>添加是否成功</returns>public bool AddBBSCategory(string name, string des){ StringBuilder strSQL = new StringBuilder();SqlParameter[] newsParms =new SqlParameter[] {new SqlParameter("@name", SqlDbType.NVarChar,50),new SqlParameter("@des", SqlDbType.NVarChar,100)};SqlCommand cmd = new SqlCommand();newsParms[0].Value = name;newsParms[1].Value = des;foreach (SqlParameter parm in newsParms)cmd.Parameters.Add(parm);using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)){strSQL.Append("Insert into BBSCategory values(@name, @des)");conn.Open();cmd.Connection = conn;cmd.CommandType = CommandType.Text;cmd.CommandText = strSQL.ToString();int val = cmd.ExecuteNonQuery();cmd.Parameters.Clear();if (val>0)return true;elsereturn false;}}}
2 回答

拉莫斯之舞
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊
正規(guī)的語(yǔ)句:Insert into BBSCategory(字段,字段) values(@字段, @字段)
而Insert into BBSCategory values(@字段, @字段) 表示表里只有兩個(gè)字段(列)

ibeautiful
TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
數(shù)據(jù)庫(kù)的列多于你要插入的列,要寫(xiě)完整你要插入的列或插入特定列時(shí),寫(xiě)清你要插入的列名在表明和values之間
添加回答
舉報(bào)
0/150
提交
取消