开发者

Inserting records permanetly into sql server using c#

I created a database in sql server express edition, in that i create a table called employee. Now i am able to inserting rows(records) dynamically into table successfully, and i can also read those records successfully. But the problem is the values which are inserted dynamically are stored temporarily. When i close and reopen the application the previous inserted records are not available. can u please suggest me what can i do to save records permanently into the database.

thanking you.....

This is my code used to inserting the records into sql server database. Please help me out of this problem...

namespace VACS_practice
{
    public partial class Form1 : Form
    {
        string m_sVehicleNo, m_sName, m_sFlatNo, m_sImagpath;
        System.Data.SqlClient.SqlConnection Con;
        System.Data.SqlClient.SqlCommand Cmd;
        string ConString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\VACSDB.mdf;Integrated Security=True;User Instance=True";

        public Form1()
        {
            InitializeComponent();
        }

        private void btnAddClick(object sender, EventArgs e)
        {

            Con = new SqlC开发者_运维百科onnection(ConString);
            m_sVehicleNo = m_VehicleNo.Text;
            m_sName = m_Name.Text;
            m_sFlatNo = m_Phno.Text;
            //m_sImagpath = m_ImgPath.Text;
            Cmd = new SqlCommand("INSERT INTO ResidentDB ([R_VehNo],[R_Name],[R_PhNo])   VALUES ('" + m_sVehicleNo + "','" + m_sName + "','" + m_sFlatNo + "')", Con);
            Con.Open();
            Cmd.ExecuteNonQuery();
            Con.Close();
            MessageBox.Show("Inserted successfully");
            // this.Close();
        }


Almost certainly you are not committing your changes. If you are running transactions then you must commit.

Alternatively, you are making changes in your in-memory versions, that are not connected to the database at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜