C#中SQL的TEXT数据类型面临的问题 [英] Problem facing with TEXT datatype of SQL in C#

查看:144
本文介绍了C#中SQL的TEXT数据类型面临的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在删除某些条件的行(在此用户是Varchar数据类型,收藏夹是Textdatatype)。但是我不知道删除查询是不行的。



但是当我直接给出这样的数据时



I am deleting a row with some conditions(In this User is Varchar datatype and Favorite is Textdatatype). But I don't know delete query is not working.

But when I gave the data directly like this

string delquery = "Delete from Parameter Where Group = 'Favoriten'  AND User = ?  AND Favorite Like  'DeliverySchedule'"

。然后我的删除查询正在运行。但是传递参数是行不通的。有人可以在这个问题上帮助我吗?



我尝试了什么:



.Then my delete query is working. But passing with parameters is not working. Can someone help me in this issue?

What I have tried:

 private void deleteItem_Click(object sender, RoutedEventArgs e)
 {
            OleDbConnection oledbconn = dvxr.getconnR46D100();
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            try
            {
                string username = dvxr.mDVXRT.usercode.ToString();
                string favname = dvxr.mDVXRT.favoritename.ToString();
                string delquery = "Delete from Parameter Where Group = 'Favoriten'  AND User = ?  AND Favorite Like ? ";
                OleDbCommand olecmd = new OleDbCommand(delquery, oledbconn);
                olecmd.Parameters.AddWithValue("@uid", username);
                olecmd.Parameters.AddWithValue("@fname", favname);
                oleda.DeleteCommand = olecmd;
                olecmd.ExecuteNonQuery();
                oledbconn.Close(); 
                MessageBox.Show("Favorite is Deleted");
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }

}

推荐答案

我们无法分辨:我们不知道你的是什么数据看起来像,或用户名 favname 包含。



所以,这取决于你。

幸运的是,你有一个工具可以帮助你找到正在发生的事情:调试器。



在函数的第一行放置一个断点,然后通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
We can't tell: we have no idea what your data looks like, or what username or favname contain.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


这篇关于C#中SQL的TEXT数据类型面临的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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