运行时查询表格出错 [英] Error in Enquiry Form on run time

查看:100
本文介绍了运行时查询表格出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行时错误...

在我的查询表格中..请帮助我...

asp.net with c#,sql server

i需要你的帮助..请支付


eroor消息是:



发生了错误!尝试AgainSystem.ArgumentException:从对象类型System.Web.UI.WebControls.TextBox到已知的托管提供程序本机类型不存在映射。 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 System.Data.SqlClient上的System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior,String commandText,SqlParameterCollection parameters,_SqlRPC& rpc)中的System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser解析器,SqlParameterCollection参数)中的isCommandProc。 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String)中的SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async,Int32 timeout,Task& task,Boolean asyncWrite,SqlDataReader ds) System.Data.SqlClient.SqlCommand中的方法,TaskCompletionSource`1完成,Int32超时,任务和任务,布尔asyncWrite) .InternalExecuteNonQuery(TaskCompletionSource`1完成,String methodName,Boolean sendToPipe,Int32超时,布尔asyncWrite)在System2.Data.SqlClient.SqlCommand.ExecuteNonQuery()在Corporate2.Button1_Click(对象发件人,EventArgs e)感谢您的应用,我们将回复很快就会申请











我的.cs页面代码:

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:

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();

       }

推荐答案

我没有运行你的代码,但可以看到错误一见钟情。



I didn't run your code, but can see a error on first sight.

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





我认为txtInstitute是你的TextBox吗?所以,你错过了给txtInstitute.Text,这就是为什么它显示类型不匹配错误。



谢谢!



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

Thanks!


你能给我这些参数的sql数据类型。?



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);
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);


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("").


这篇关于运行时查询表格出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆