问题描述
SqlConnectioncn;StringstrConnection=ConfigurationSettings.AppSettings["ConnectionString"];//公用cn=newSqlConnection(strConnection);SqlCommandcm=newSqlCommand("tijiao1",cn);cm.CommandType=CommandType.StoredProcedure;cm.Parameters.Add(newSqlParameter("@title",SqlDbType.VarChar,50));cm.Parameters.Add(newSqlParameter("@content",SqlDbType.VarChar,50));cm.Parameters["@title"].Value=TextBox1.Text;cm.Parameters["@content"].Value=TextBox2.Text;try{cm.Connection.Open();stringflag=cm.ExecuteScalar().ToString();if(flag>0){Response.Write("<scriptlanguage=javascript>alert('注册成功')</script>");}else{Response.Write("<scriptlanguage=javascript>alert('注册失败!请检查输入是否符合要求')</script>");}cm.Connection.Close();}catch(System.Exceptionee){Response.Write("<scriptlanguage=javascript>alert('"+ee.Message.ToString()+"')</script>");}finally{cm.Connection.Close();}}
解决方案
解决方案二:
intflag=int.Parse(cm.ExecuteScalar().ToString());if(flag>0){Response.Write("<scriptlanguage=javascript>alert('注册成功')</script>");}else{Response.Write("<scriptlanguage=javascript>alert('注册失败!请检查输入是否符合要求')</script>");}cm.Connection.Close();
解决方案三:
(int)Convert.
解决方案四:
上面提示:未将对象引用设置到对像的实例ExecuteNonQueryExecuteScalar这两有什么区别?