简体   繁体   English

努力将记录从我的C#WinForm应用程序插入“ SQL Server Compact 4.0数据库”。 (我正在使用VS 2010)

[英]Struggling to insert record into “SQL Server Compact 4.0 Database” from my C# WinForm Application. (I'm using VS 2010))

In my C# Winform Application I have written a code to insert record into the "SQL Server Compact 4.0 Database". 在我的C#Winform应用程序中,我编写了代码以将记录插入“ SQL Server Compact 4.0数据库”。 Also I had debug code line-by-line everything is working fine (without any error) but after insert functionality when I checked my database I found that record is not inserted into the database, I'm strange why it is happening..! 我也逐行调试了代码,一切都工作正常(没有任何错误),但是当我检查数据库时插入功能之后,发现记录未插入数据库中,我很奇怪为什么会发生..!

But I think it is happening because, "when I tried to add database in my project I got this error " Following is my code to insert record into the database-- 但我认为这是因为“在尝试在项目中添加数据库时出现此错误 ”, 是我将代码插入数据库的代码,

// Retrieve the connection string from the settings file.
string conString = Properties.Settings.Default.snda_dbConnectionString;

//string conString = "Data Source=|DataDirectory|\\db_snda.sdf";
try
{
    conString = conString +";Password = test@1;";

    // Open the connection using the connection string.
    using (SqlCeConnection con = new SqlCeConnection(conString))
    {
        con.Open();

        // Read in all values in the table.
        using (SqlCeCommand cmd = new SqlCeCommand("INSERT INTO tbl_user_master" + "(user_id, password, user_type, user_title, first_name, middle_name, last_name, gender, dob, mobile_no, email_id, plant_code, div_code, region_code, reporting_to, releaving_date, created_date)" + " VALUES(@user_id, @password, @user_type, @user_title, @first_name, @middle_name, @last_name, @gender, @dob, @mobile_no, @email_id, @plant_code, @div_code, @region_code, @reporting_to, @releaving_date, @created_date)", con))
        {
            cmd.Parameters.AddWithValue("@user_title", strTitle);
            cmd.Parameters.AddWithValue("@first_name", strFirstName);
            cmd.Parameters.AddWithValue("@middle_name", strMiddleName);
            cmd.Parameters.AddWithValue("@last_name", strLastName);
            cmd.Parameters.AddWithValue("@gender", strGender);
            cmd.Parameters.AddWithValue("@user_type", strUserType);
            cmd.Parameters.AddWithValue("@plant_code", strPlantCode);
            cmd.Parameters.AddWithValue("@div_code", strDivCode);
            cmd.Parameters.AddWithValue("@region_code", strRegionCode);
            cmd.Parameters.AddWithValue("@reporting_to", strReportingTo);
            cmd.Parameters.AddWithValue("@user_id", strUserName);
            cmd.Parameters.AddWithValue("@password", Encrypt(strPassword));  //Encrypt(strPassword)
            cmd.Parameters.AddWithValue("@email_id", strEmailId);
            cmd.Parameters.AddWithValue("@mobile_no", strMobileNo);
            cmd.Parameters.AddWithValue("@dob", strDOB);
            cmd.Parameters.AddWithValue("@created_date", strCreatedDate);
            cmd.Parameters.AddWithValue("@releaving_date", strReleavingDate);

            cmd.ExecuteNonQuery();                           
        }

        con.Close();

        XtraMessageBox.Show("User Created Successfully.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
        ResetAfterSubmit();
    }
}
catch (Exception ex)
{
   MessageBox.Show(ex.ToString());
}

Thank you...! 谢谢...!

It is hapening because you mix up databases - the one you check is not the one that is used during insert as likely when you start the debugging of the program a copys created in the output folder - and then discarded when you stop the program. 之所以会令人发笑,是因为您混淆了数据库-您检查的数据库不是在插入程序期间使用的数据库,因为当您开始调试程序时,将在输出文件夹中创建一个副本-然后在停止程序时将其丢弃。

This is not exactly a rare problem and a good indication of someone not using a search function to find a solution. 这并不是一个罕见的问题,并且很好地表明了有人没有使用搜索功能来找到解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#程序正在寻找sql server compact 3.5,但我使用的是4.0 - C# program is looking for sql server compact 3.5, but I'm using 4.0 将记录插入到SQL Server CE数据库移动到另一个线程? C#Compact Framework 3.5 - Move record insert to SQL Server CE database into another thread? C# Compact Framework 3.5 C#,SQL Server Compact-优化插入记录速度 - C#, SQL Server Compact - optimize insert record speed 如何使用C#.NET Winform从SQL Server Compact数据库检索返回行值 - How to retrieve return row value from a SQL Server Compact database using C#.NET winform 如何检查SQL Server数据库C#winform中是否存在记录? - How to check if a record exists in the SQL Server database C# winform? 我正在尝试从SQL Server Compact数据库中读取数据,但是我一直收到相同的错误 - I'm trying to read data from my SQL Server Compact database, but I keep getting the same error 具有Microsoft SQL Server数据库的C#Winform应用程序 - C# winform application with Microsoft SQL Server database 如何使用C#在Windows窗体应用程序中的SQL Server Compact数据库中搜索? - How to Search in SQL Server Compact Database in windows form application using C#? C#SQL Server Compact插入解决方案 - C# SQL Server Compact Insert solution C#SQL Server Compact数据库登录 - C# SQL Server Compact Database Login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM