Getting error like this in below Code
Error :System.ArgumentException: No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type. at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen) at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly() at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc) at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters) at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Human_resource_management.Add_Employee.Button1_Click(Object sender, EventArgs e) in D:\C Sharp(#)\Project\Human resource management\Human resource management\Add Employee.aspx.cs:line 52
Here Is the Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace Human_resource_management
{
public partial class Add_Employee : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HumanResourceManagementConnectionString"].ConnectionString);
conn.Open();
SqlCommand Command = new SqlCommand();
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HumanResourceManagementConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into HR (EMPID,EMPNAME,DEPARTMENT,QUALIFICATION,DEGREE,YEAR,BOARD,EXPERIENCE,GENDER,DATEOFBIRTH,MARTIALSTATUS,CONTACTNO,EMAIL,POSTALADDRESS,CITY,COUNTRY,DATEOFJOINING,SALARY) values(@empid ,@empname ,@department ,@qualification ,@degree ,@year ,@board ,@experience ,@gender ,@dateofbirth ,@martialstatus ,@contactno ,@email ,@postaladdress ,@city ,@country ,@dateofjoining ,@salary)";
SqlCommand Command = new SqlCommand(insertQuery, conn);
Command.Parameters.AddWithValue("@empid",txt_ID.Text );
Command.Parameters.AddWithValue("@empname", txt_Name.Text );
Command.Parameters.AddWithValue("@department", txt_Dep.Text);
Command.Parameters.AddWithValue("@degree", txt_D1.Text);
Command.Parameters.AddWithValue("@year", txt_Y1.Text);
Command.Parameters.AddWithValue("@board", txt_B1.Text);
Command.Parameters.AddWithValue("@experience", txt_Exp.Text);
Command.Parameters.AddWithValue("@gender", txt_Gender.Text);
Command.Parameters.AddWithValue("@dateofbirth", txt_DOB);
Command.Parameters.AddWithValue("@contactno", txt_Contactno.Text);
Command.Parameters.AddWithValue("@email", txt_Email.Text);
Command.Parameters.AddWithValue("@city", txt_City.Text);
Command.Parameters.AddWithValue("@country", txt_Country.Text);
Command.Parameters.AddWithValue("@dateofjoining", txt_DateofJoin.Text);
Command.Parameters.AddWithValue("@salary", txt_Salary.Text);
Command.ExecuteNonQuery();
Response.Write("Employee Hired");
Response.Write("Manage Employees.aspx");
conn.Close();
}
catch(Exception ex)
{
Response.Write("Error :"+ex.ToString());
}
}
}</pre>