关闭应用程序后清理SQL数据 [英] SQL data is cleaned after closing application

查看:70
本文介绍了关闭应用程序后清理SQL数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在将数据输入到sql中并关闭我的应用程序后,我输入的所有数据都松散了,我遇到了这个问题!
这是我的代码:

Hi,
I have this problem, after I enter data into my sql and I close my app all the data that I have entered loose!
this is my code :

public void Save(string name, string family, string crime, string address, string prisonedtime)
        {
            connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename="+path()+"\\SavabeghDataBase.mdf;Integrated Security=True;User Instance=True");
            command = new SqlCommand("INSERT INTO SavabeghTable(Name,Family,Crime,Address,PrisonedTime) VALUES(@name,@family,@crime,@address,@prisonedtime)", connection);
            command.Parameters.AddWithValue("@name", name);
            command.Parameters.AddWithValue("@family", family);
            command.Parameters.AddWithValue("@crime", crime);
            command.Parameters.AddWithValue("@address", address);
            command.Parameters.AddWithValue("@prisonedtime", prisonedtime);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }

private string path()
        {
            string path = Application.ExecutablePath.ToString();
            string[] s = path.Split('\\');
            path = string.Empty;
            for (int i = 0; i < s.Length-1; i++)
            {
                path += s[i];
                if (i < s.Length - 2)
                    path += "\\";
            }
            return path;
        }







please help me about this!

推荐答案

您要做的第一件事是在Save方法的第一行上放置一个断点,并确保您正在执行它.
如果是的话,那么请单步执行并确保您不会在更高层次上吞下异常.

如果是这样,则遍历该方法时请检查路径是否正确.

让我们知道您找到了什么!
The first thing you want to do is to put a breakpoint on the first line of your Save method, and ensure that you are executing it.
If you are, then single step through and make sure you don''t get an exceptions which you are swallowing at a higher level.

If so, then check that the path is correct as you go through the method.

Let us know what you find!


这篇关于关闭应用程序后清理SQL数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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