更新时间:2023-11-20 18:26:28
看起来你没有在行中传递正确的SP名称 - SqlCommand command = new SqlCommand( spAllinone,connect);
连接字符串错误。 DataBase这里的名字在哪里?指定。
请从此处按照相应的连接字符串 - http://connectionstrings.com / 。
i have created a stored procedure named storedproceed. the code i done in class file is as :
public class Class1
{
private int _Event;
private int _EmpId;
private string _EmpName;
private int _Salary;
private string _City;
private int _Atype;
public int Event
{
get { return _Event; }
set { Event = value; }
}
public int EmpId
{
get { return _EmpId; }
set { _EmpId = value; }
}
public string EmpName
{
get { return _EmpName; }
set { _EmpName = value; }
}
public int Salary
{
get { return _Salary; }
set { _Salary = value; }
}
public string City
{
get { return _City; }
set { _City = value; }
}
public int Atype
{
get { return _Atype; }
set { _Atype = value; }
}
public void save()
{
String constr = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
SqlConnection connect = new SqlConnection(constr);
SqlCommand command = new SqlCommand("spAllinone", connect);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@event", SqlDbType.TinyInt).Value = Atype;
command.Parameters.Add("@EmpId", SqlDbType.Int).Value = EmpId ;
command.Parameters.Add("@Emp_name", SqlDbType.NVarChar,50).Value = EmpName ;
command.Parameters.Add("@Salary", SqlDbType.Int).Value = Salary ;
command.Parameters.Add("@City", SqlDbType.NVarChar,50).Value = City ;
connect.Open();
command.ExecuteNonQuery();
command.Connection.Close();
the code in my .cs file i as :
protected void Button1_Click(object sender, EventArgs e)
{
Class1 obj = new Class1();
obj.EmpId = Convert.ToInt32(txtEmpId.Text);
obj.EmpName = txtEmpName.Text;
obj.Salary = Convert.ToInt32(txtSalary.Text);
obj.City = txtCity.Text;
obj.Atype = Convert.ToInt32(txtEvent.Text);
obj.save();
what the problem is when i debug my program it gives error that stored procedure is not found.why?even i check it is present in database.
Looks like you are not passing in the right SP name in the line - SqlCommand command = new SqlCommand("spAllinone", connect);
The Connection string is wrong. Where is the DataBase name here? Specify that.
Please follow the appropriate connection string from here - http://connectionstrings.com/.