这个是什么错误啊郁闷
public int AddTitle(int classid, string title, string text, string photo)
{
StringBuilder strSql = new StringBuilder();
SqlCommand cmd = new SqlCommand();
SqlParameter pclassid = new SqlParameter("@vclassid", SqlDbType.Int, 4);
SqlParameter ptitle = new SqlParameter("@vtitle", SqlDbType.NVarChar, 100);
SqlParameter ptext = new SqlParameter("@vtext", SqlDbType.NVarChar, 8000);
SqlParameter pphoto = new SqlParameter("@vphoto", SqlDbType.NVarChar, 50);
pclassid.Value=vclassid;
ptitle.Value = vtitle;
ptext.Value = vtext;
pphoto.Value = vphoto;
cmd.Parameters.Add(pclassid);
cmd.Parameters.Add(ptitle);
cmd.Parameters.Add(ptext);
cmd.Parameters.Add(pphoto);
SqlConnection con = DB.con();
int nResult = -1;
try
{
strSql.Append(addtitle);
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql.ToString();
nResult = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
catch (SqlException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
con.Close();
}
return nResult;
}
老说这一句 :nResult = cmd.ExecuteNonQuery();
字符串格式不正确 大家帮我看看吧 谢谢了
我是这样用的
protected void Button1_Click(object sender, EventArgs e)
{
int adclass = Convert.ToInt32(classid.SelectedValue);
string adtitle = title.Text;
string adphoto = photo.Text;
string adtext = FCKeditor1.Value;
//string project = project;
Title addtitle = new Title();
addtitle.AddTitle(adclass, adtitle, adtext, adphoto);
Response.Write("添加成功");
Response.Write(adtitle+"<br>"+adclass+"<br>"+adphoto+"<br>"+adtext+"<br>");
}
------解决方案--------------------ExecuteNonQuery();
缺少参数
------解决方案--------------------C# code
nResult = cmd.ExecuteNonQuery();
------解决方案--------------------
没看到你的SQL语句阿?
strSql="insert into.....";
加一条SQL语句看看