我该如何解决这个错误? [英] How do I fix this bug?

查看:79
本文介绍了我该如何解决这个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的程序员,



每次我尝试执行此代码时,都会在command.ExecuteScalar();

时给出错误



Dear programmers,

Every time i try to execute this code it gives me an error at command.ExecuteScalar();


private void btnAddRecht_Click(object sender, EventArgs e)
       {
           String query = "INSERT INTO Samenvatting VALUES (@MedewerkersId, @rechtId)";

           using (connection = new SqlConnection(connectionString))
           using (SqlCommand command = new SqlCommand(query, connection))
           {
               connection.Open();

               command.Parameters.AddWithValue("@MedewerkersId", listBoxMedewerkers.SelectedValue);
               command.Parameters.AddWithValue("@rechtId", listBoxAllRechten.SelectedValue);

               command.ExecuteScalar();
           }

           vulMedewerkers();
       }





我尝试过:





What I have tried:

There is no assignment of object type System.Data.DataRowView to a known native type of a managed provider. '

推荐答案

1。我建议学习调试你的代码,因为你得到的错误不在command.ExecuteScalar()上,而是在它之前的一个命令之上。

2. .SelectedValue在你的一个或两个控件上是DataRowView而不是String。因此,您需要查看它是什么类型的控件以及如何将选定值作为字符串。

3.发布一个合适的标题,以便人们在寻找问题以回答他们知道你的意思。
1. I suggest learning to debug your code because the error you are getting is not on command.ExecuteScalar() but on one of the commands before it.
2. .SelectedValue on one or both of your controls is a DataRowView and not a String. So, you need to look at what type of control it is and how to get the Selected Value as a string.
3. Post an appropriate title so as people are looking for questions to answer they know what yours is about.


看看你的错误信息:它很清楚。

一个(或多个)参数值是DataRowView,SQL不知道如何处理它。



使用调试器,找出您尝试传递的值,然后传递标准值。我们不能为您做到这一点,因为我们没有您的代码,我们没有您的数据,如果我们这样做,我们也不知道如何处理它!
Look at your error message: it's pretty clear.
One (or more) of your parameter values is a DataRowView and SQL does not know what to do with it.

Use the debugger, find out what values you are trying to pass, and then pass a standard value instead. We can't do that for you as we don't have your code, we don't have your data, and we wouldn't know what to do with it if we did!


这篇关于我该如何解决这个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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