Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am having a run time error...
on my enquiry form..please help me out...
asp.net with c#, sql server
i need your help..please

eroor message is:

Error Occured! Try AgainSystem.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, Boolean streamAllowed) 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, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Corporate2.Button1_Click(Object sender, EventArgs e)Thanks for Applying, We will response on your application shortly





my .cs page code:
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       try
       {
           string str = "Data Source=HP-PC\\SQLEXPRESS;Initial Catalog=Earth;Integrated Security=True";
           SqlConnection con = new SqlConnection(str);
           con.Open();
           string insertQuery = "insert into Current (Name,Emailaddress,Contactno,Qualification,Institute) values (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";
           SqlCommand com = new SqlCommand(insertQuery, con);
           com.Parameters.AddWithValue("@Name", txtName.Text);
           com.Parameters.AddWithValue("@Emailaddress", txtEmailaddress.Text);
           com.Parameters.AddWithValue("@Contactno", txtContactno.Text);
           com.Parameters.AddWithValue("@Qualification", txtQualification.Text);
           com.Parameters.AddWithValue("@Institute", txtInstitute);
           //com.Parameters.AddWithValue("@Institutename", txtInstitutename.Text);
           //com.Parameters.AddWithValue("@Description", txtDescription.Text);


           com.ExecuteNonQuery();



           con.Close();

       }
Posted
Updated 4-Mar-14 20:15pm
v2

Add CommentType

com.CommandType=CommandType.Text;





protected void Button1_Click(object sender, EventArgs e)
{
try
{
string str = "Data Source=HP-PC\\SQLEXPRESS;Initial Catalog=Earth;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
con.Open();
string insertQuery = "insert into Current (Name,Emailaddress,Contactno,Qualification,Institute) values (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";
SqlCommand com = new SqlCommand(insertQuery, con);
com.CommandType=CommandType.Text;
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Emailaddress", txtEmailaddress.Text);
com.Parameters.AddWithValue("@Contactno", txtContactno.Text);
com.Parameters.AddWithValue("@Qualification", txtQualification.Text);
com.Parameters.AddWithValue("@Institute", txtInstitute.Text);
//com.Parameters.AddWithValue("@Institutename", txtInstitutename.Text);
//com.Parameters.AddWithValue("@Description", txtDescription.Text);


com.ExecuteNonQuery();



con.Close();

}
 
Share this answer
 
C#
try
{
    SqlConnection con = conn;
    SqlCommand cmd = new SqlCommand();
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "insert into Current (Name,Emailaddress,Contactno,Qualification,Institute) values
    (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";

    cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = (txtName.Text == null) ? DBNull.Value : txtName.Text;

    cmd.Parameters.Add("@Emailaddress", SqlDbType.VarChar).Value = (txtEmailaddress.Text == null) ? DBNull.Value : txtEmailaddress.Text;

    cmd.Parameters.Add("@Contactno", SqlDbType.VarChar).Value = (txtContactno.Text == null) ? DBNull.Value : txtContactno.Text;

    cmd.Parameters.Add("@Qualification", SqlDbType.VarChar).Value = (txtQualification.Text == null) ? DBNull.Value : txtQualification.Text;

    cmd.Parameters.Add("@Institute", SqlDbType.VarChar).Value = (txtInstitute.Text == null) ? DBNull.Value : txtInstitute.Text;

    cmd.Connection = con;
    con.Open();
    int i = cmd.ExecuteNonQuery();
    con.Close();
}
catch (Exception ex)
{
}
 
Share this answer
 
try this

protected void Button1_Click(object sender, EventArgs e)
{
try
{
string str = "Data Source=HP-PC\\SQLEXPRESS;Initial Catalog=Earth;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
con.Open();
string insertQuery = "insert into Current (Name,Emailaddress,Contactno,Qualification,Institute) values (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";
SqlCommand com = new SqlCommand(insertQuery, con);
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Emailaddress", txtEmailaddress.Text);
com.Parameters.AddWithValue("@Contactno", txtContactno.Text);
com.Parameters.AddWithValue("@Qualification", txtQualification.Text);
com.Parameters.AddWithValue("@Institute", txtInstitute.Text);// add .Text
//com.Parameters.AddWithValue("@Institutename", txtInstitutename.Text);
//com.Parameters.AddWithValue("@Description", txtDescription.Text);


com.ExecuteNonQuery();



con.Close();

}
 
Share this answer
 
"Current" Table name not supported by SQL Server because "Current" is a reserved Keyword.
So you have two options:
1. You can rename the table to something else (say 'Current_T')
2. modify the query as following:
SQL
INSERT INTO [Current](Col1, Col2) values (val1, val2)


Note the square bracket around the table name.
 
Share this answer
 
v2
Comments
manishmns12 5-Mar-14 2:19am    
sir i have changed the table name to Currentrecruitment

it will work no????
Aravindba 5-Mar-14 2:24am    
what u get error ? did u try solution 5 ?
Hai
Try like this,use square bracket for table name and column name

C#
string insertQuery = "insert into [Current]([Name],[Emailaddress],[Contactno],[Qualification],[Institute]) values (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";
SqlCommand com = new SqlCommand(insertQuery, con);
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Emailaddress", txtEmailaddress.Text);
com.Parameters.AddWithValue("@Contactno", txtContactno.Text);
com.Parameters.AddWithValue("@Qualification",  txtQualification.Text);
com.Parameters.AddWithValue("@Institute", txtInstitute.Text);



if u pass text value directly so use textbox.text,if u pass string then use string with double qutos("Institute") like above answer.

Regards
Aravind
 
Share this answer
 
v3
Please change Table name then execute successfully.

string insertQuery = "insert into Current1(Name,Emailaddress,Contactno,Qualification,Institute) values (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";
SqlCommand com = new SqlCommand(insertQuery, con);
com.Parameters.AddWithValue("@Name", "Test");
com.Parameters.AddWithValue("@Emailaddress", "TestEmail");
com.Parameters.AddWithValue("@Contactno", "TestContact");
com.Parameters.AddWithValue("@Qualification", "TestQualification");
com.Parameters.AddWithValue("@Institute", "TestInsitute");
 
Share this answer
 
Comments
manishmns12 5-Mar-14 2:10am    
com.Parameters.AddWithValue("@Name", "Test");


com.Parameters.AddWithValue("@Name", txtName.Text);

sir which one is right??
Null value must have been passed to the sql server as a parameter value. Its recommended you to check for null value and change it either to DBNull.Value or empty quotes("").
 
Share this answer
 
Comments
manishmns12 5-Mar-14 1:41am    
sorry sir but didnt undrstood...
cn u help me som,e more please.....
where to make what changes please...
MukeshSinha 5-Mar-14 1:59am    
Please change table name then execute sucess
manishmns12 5-Mar-14 1:55am    
please look at my issue nad help me out
MukeshSinha 5-Mar-14 2:00am    
Please change table name then execute sucess
manishmns12 5-Mar-14 2:09am    
ok i m doing...but sir does the table name can cause issues...??
plz gv me guidance sir....
waiting for ur reply
Hi, Can You give me sql data type of these parameter.?

com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Emailaddress", txtEmailaddress.Text);
com.Parameters.AddWithValue("@Contactno", txtContactno.Text);
com.Parameters.AddWithValue("@Qualification", txtQualification.Text);
com.Parameters.AddWithValue("@Institute", txtInstitute.Text);
 
Share this answer
 
Comments
manishmns12 5-Mar-14 1:28am    
Name nvarchar(50)
Emailaddress nvarchar(50)
Contactno varchar(50)
Qualification nvarchar(50)
Institute nvarchar(MAX)
manishmns12 5-Mar-14 1:54am    
please sir..hellp me frm this issue......
I didn't run your code, but can see a error on first sight.

C#
com.Parameters.AddWithValue("@Institute", txtInstitute);


I think txtInstitute is your TextBox right ? So, you missing to give txtInstitute.Text and thats why It show the type mismatch error.

Thanks!
 
Share this answer
 
Comments
manishmns12 5-Mar-14 0:44am    
sir still a error is coming...
please help me abt this issue
error msg is:

Error Occured! Try AgainSystem.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'Current'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Corporate2.Button1_Click(Object sender, EventArgs e) ClientConnectionId:90c4dbcb-71c0-4fff-809a-575c7a45d272Thanks for Applying, We will response on your application shortly
manishmns12 5-Mar-14 1:08am    
please sir make a reply..plz help me out
manishmns12 5-Mar-14 1:54am    
please sir....help me out....
ErBhati 5-Mar-14 2:19am    
try this
insert into [Current]([Name],Emailaddress,Contactno,Qualification,Institute) values (@Name,@Emailaddress,@Contactno,@Qualification,@Institute)";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900