Ошибка преобразования типа данных varchar в int.
Привет , у меня есть ошибка типа преобразования в GridView при добавлении сведений о сотруднике.Я использовал хранимую процедуру.
Что я уже пробовал:
ALTER PROCEDURE [dbo].[gvempdetails] @Action VARCHAR (10), @EMPLOYEEID Int =0, @EMPLOYEENAME VARCHAR(100)= NULL , @DEPARTMENT VARCHAR(100)= NULL , @AGE VARCHAR(30)= NULL, @SALARY INT = NULL AS BEGIN SET NOCOUNT ON IF @Action = 'SELECT' BEGIN SELECT EmpId,EmpName,Dep,Age,Sal FROM gvdetails17 END IF @Action='INSERT' BEGIN INSERT INTO gvdetails17(EmpId,EmpName,Dep,Age,Sal) VALUES(@EMPLOYEEID,@EMPLOYEENAME,@DEPARTMENT,@AGE,@SALARY) END IF @Action ='UPDATE' BEGIN UPDATE gvdetails17 SET EmpName=@EMPLOYEENAME,Dep=@DEPARTMENT,Age=@AGE,Sal=@SALARY WHERE EmpId=@EMPLOYEEID END IF @Action='DELETE' BEGIN DELETE FROM gvdetails17 where EmpId=@EMPLOYEEID END SET NOCOUNT OFF END
с фоновым кодом
protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Add")) { TextBox txtEmpId = (TextBox)gvDetails.FooterRow.FindControl("txtempid"); TextBox txtEmpName = (TextBox)gvDetails.FooterRow.FindControl("txtempname1"); TextBox txtEmpDep = (TextBox)gvDetails.FooterRow.FindControl("txtdep1"); TextBox txtAge = (TextBox)gvDetails.FooterRow.FindControl("txtage1"); TextBox txtSal = (TextBox)gvDetails.FooterRow.FindControl("txtsal1"); string Id = (txtEmpId.Text); string name = txtEmpName.Text; string department = txtEmpName.Text; string age = txtEmpDep.Text; string salary = txtEmpDep.Text; INSERTEmployee(Id, name, department, age, salary); gvDetails.EditIndex = -1; bind(); } } protected void INSERTEmployee(string Id, string name, string department, string age, string salary) { SqlCommand cmd = new SqlCommand(); cn.Open(); cmd.Connection = cn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "gvempdetails22"; cmd.Parameters.Add(new SqlParameter("@Action", SqlDbType.VarChar, 50)); cmd.Parameters.Add(new SqlParameter("@EMPLOYEEID", SqlDbType.VarChar, 50)); cmd.Parameters.Add(new SqlParameter("@EMPLOYEENAME", SqlDbType.VarChar, 50)); cmd.Parameters.Add(new SqlParameter("@DEPARTMENT", SqlDbType.VarChar, 50)); cmd.Parameters.Add(new SqlParameter("@AGE", SqlDbType.VarChar, 50)); cmd.Parameters.Add(new SqlParameter("@SALARY", SqlDbType.VarChar, 50)); cmd.Parameters["@Action"].Value = "INSERT"; cmd.Parameters["@EMPLOYEEID"].Value = Id; cmd.Parameters["@EMPLOYEENAME"].Value = name; cmd.Parameters["@DEPARTMENT"].Value = department; cmd.Parameters["@AGE"].Value = age; cmd.Parameters["@SALARY"].Value = salary; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); gvDetails.DataSource = ds; gvDetails.DataBind(); cn.Close();
Ehsan Sajjad
можете ли вы опубликовать подробную информацию об исключении и конкретно о том, в какой строке оно происходит?