简体   繁体   English

数据未使用C#和Visual Studio保存在数据库中

[英]Data not saving in database using C# and Visual Studio

I have a project that used to work fine last time I worked on it, but after I formatted the PC the program couldn't find the database, the solution I found was to use this : 我有一个上次使用它时可以正常工作的项目,但是在格式化PC后,程序找不到数据库,我发现的解决方案是使用此方法:

SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|PAPPloran.mdf;Integrated Security=True;Connect Timeout=30");

Instead having the full path for the database file location. 而是具有数据库文件位置的完整路径。

That was the change that might be causing my problem, data isn't being saved on database anymore, it is shown on a datagridview on program after I "save" but when I close and reopen the program isn't there anymore. 那是可能导致我的问题的更改,数据不再保存在数据库中,而是在我“保存”后显示在程序的datagridview上,但是当我关闭并重新打开程序后,该程序就不再存在。

Example from my program of a save button: 我的程序中有一个保存按钮的示例:

private void fusionButton1_Click(object sender, EventArgs e)
{
    {
        if (textBox1.Text != "" & dateTimePicker1.Text != "" & textBox3.Text != "" & textBox4.Text != "" & textBox5.Text != "" & comboBox2.Text != "" & textBox7.Text != "" & textBox8.Text != "" & textBox9.Text != "")
        {
            cn.Open();
            cmd.CommandText = "INSERT INTO Pagamentos ( NomeFornecedor, NFatura, Data, Valor, IVA, Total, Situacao, MPagamento, Dataliquidacao, Obs) VALUES ( '" + comboBox1.Text + "', '" + textBox1.Text + "', '" + dateTimePicker1.Text + "', '" + textBox3.Text + "' , '" + textBox4.Text + "','" + textBox5.Text + "', '" + comboBox2.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "')";
            cmd.ExecuteNonQuery();
            cmd.Clone();
            MessageBox.Show("Pagamento Inserido");
            cn.Close();
        }
    }
}

查看bin / debug文件夹,您将在其中找到databasr文件的副本(其中包含数据)

暂无
暂无

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

相关问题 使用C#从Visual Studio将数据插入Access数据库中 - Inserting Data in an Access Database from Visual Studio using C# 使用C#中的Visual Studio通过MySQL将数据插入数据库 - Insert Data into database via mySQL using visual studio in C# 使用C#中的fileuploadControl将数据保存到数据库 - Saving Data to Database using fileuploadControl in C# 使用Visual Studio C#在Management Studio中编辑数据库 - Edit database in management studio using visual studio c# 使用C#,WPF,实体框架和Visual Studio 2012不会在数据库中更新数据 - Data is not updated in database, using C#,WPF, Entity framework and Visual studio 2012 如何使用Visual Studio和C#将数据插入数据库并将其保存到数据库中? - How can I insert and save data into database using Visual Studio and C#? C#:如何从数据库的最后一行获取数据? 我在Visual Studio 2017中使用 - C#: How to get data from the last row in database? I'm using in visual studio 2017 Visual Studio Web应用程序使用C#将数据发送到SQL数据库的问题(cmd.ExecuteNonQuery();) - Visual Studio Web Application using C# to send data to a SQL database issues (cmd.ExecuteNonQuery();) 如何使用C#将数据插入SQL Sever而不使用数据库向导(visual studio) - How To insert data into SQL Sever with C# without using the database wizard(visual studio) 如何在Visual Studio中从数据库中获取数据时使HTML行可单击(使用C#) - How to make an HTML row clickable while fetching data from the database (Using C#) in visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM