只有最近添加的问题才会显示在窗体C#上 [英] Only recent question added is being displayed on window form C#

查看:95
本文介绍了只有最近添加的问题才会显示在窗体C#上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有问题文件。当我选择我想要在其中带纸的主题的ID时,显示最近添加的最后一个问题而不是所有问题..



我尝试过:



i have question paper in database .when i select the id of subject in which i want to take paper in it displays the last recent question added not the all question ..

What I have tried:

<pre>public DataSet SqlDataSet(string sql)
        {
            string sqlSelect =..cmd
            SqlConnection conn = new SqlConnection(constring);
            SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            try
            {


                sda.Fill(ds);
            }
            catch (SqlException se)
            {
                MessageBox.Show("An error occured while connecting to database" + se.ToString());
            }
            finally
            {
                conn.Close();
            }
            return ds;
        }

推荐答案

首先,请停止这样做!永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。



至于您发现的问题:由于我们无法访问您的数据,我们无法提供太多帮助,因此我们无法运行你的代码,看看发生了什么,然后说这就是这个。



所以,它将取决于你。

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


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
First off, stop doing it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

As for the problem you have found: we can't really help that much as we don't have access to your data, so we can't run your code, look at what is happening, and say "it's this".

So, its going to be up to you.
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#上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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