using System;using System.Data;using System.Data.SqlClient;using System.Text;/// <summary>///BBSManager 的摘要说明/// </summary>public class BBSManager{public BBSManager(){}/// <summary>///添加论坛的类别/// </summary>/// <param name="name">类别名称</param>/// <param name="des">类别描述信息</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贡献1820条经验 获得超10个赞
正规的语句:Insert into BBSCategory(字段,字段) values(@字段, @字段)
而Insert into BBSCategory values(@字段, @字段) 表示表里只有两个字段(列)
添加回答
举报
0/150
提交
取消