添加记录时出现“未能找到存储过程”
string tempusername;
tempusername = username.Text;
string connstr;
connstr = ConfigurationSettings.AppSettings[ "connstr "];
SqlConnection conn = null;
DataSet ds = new DataSet();
conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insert into user_login(usernam) value( ' " + tempusername + " ') ";
cmd.Parameters.Add( "@username ", SqlDbType.VarChar, 10).Value = tempusername;
cmd.Connection = conn2;
SqlDataAdapter ad=new SqlDataAdapter();
ad.InsertCommand = cmd;
cmd.ExecuteNonQuery();
conn.Close();
为什么运行后说我么有找到存储过程未能找到存储过程 'insert into user_login(username) value( 'miser ') '。
(miser)是我打的用户名
------解决方案--------------------cmd.CommandType = CommandType.StoredProcedure;注释掉!
------解决方案--------------------cmd.CommandType = CommandType.StoredProcedure; //this is StoredProcedure
cmd.CommandText = "insert into user_login(usernam) value( ' " + tempusername + " ') "; /////but this is a Sql Sentence