通过V C#2008在Access 2007中未记录记录 [英] Recorde not Apending in Access 2007 thru V C# 2008

查看:77
本文介绍了通过V C#2008在Access 2007中未记录记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,请提供解决方案在文本窗口中从特定字段显示重新编码,但是当我们在Access数据库中添加任何已重新编码的内容时,就会暂时删除上一次重新编码.我已经在下面显示了源代码.

Hi, Please Provide the solution Recode is desplaying in text windows from specific field but when we Add any recoded in Access Data Base then Last recode is temprorly remove. I had show the source code below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Test_Project
{
    public partial class Form1 : Form
    {
        String MyCon = null;
        public Form1()
        {
            InitializeComponent();
            MyCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Students.mdb";
        }
        private void button6_Click(object
            sender, EventArgs e)
        {
            this.studinfoBindingSource.MovePrevious();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'studentsDataSet.Studinfo' table. You can move, or remove it, as needed.
            this.studinfoTableAdapter.Fill(this.studentsDataSet.Studinfo);
        }
        private void FirstBt_Click(object sender, EventArgs e)
        {
            this.studinfoBindingSource.MoveFirst();
        }
        private void NextBt_Click(object sender, EventArgs e)
        {
            this.studinfoBindingSource.MoveNext();
        }
        private void LastBt_Click(object sender, EventArgs e)
        {
            this.studinfoBindingSource.MoveLast();
        }
        private void NewBt_Click(object sender, EventArgs e)
        {
            RollNo.Text = null;
            NameTb.Text = null;
            FatherTb.Text = null;
            AddressTb.Text = null;
        }
        private void InsertBt_Click(object sender, EventArgs e)
        {
            String RolNo = RollNo.Text.ToString();
            String StdName = NameTb.Text.ToString();
            String StdFName = FatherTb.Text.ToString();
            String Address = AddressTb.Text.ToString();
               OleDbCommand Cmd;
               OleDbConnection Cnn;
               Cnn = new OleDbConnection(MyCon);
               String SQL = null;
               SQL = "INSERT INTO Studinfo(RollNo, Sname, SFName, Address) Values('"+RolNo+"','"+StdFName+"','"+StdFName+"','"+Address+"')";
            
            int Responce = -1;
            try
            {
                Cnn.Open();
                Cmd = new OleDbCommand(SQL,Cnn); 
                Responce = Cmd.ExecuteNonQuery();
                Cnn.Dispose(); 
                Cnn.Close();
            }
            catch (Exception ex)
             {
               MessageBox.Show(ex.Message);
             }
            if (Responce >= 1) MessageBox.Show("Record is added to database", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                NameTb.Clear();
                FatherTb.Clear();
                AddressTb.Clear();
        }      
    }
}

推荐答案

我强烈怀疑您的问题出在您的UI层中,因为没有任何东西会临时删除"数据库中的值.因此,我希望您需要查看执行顺序,我敢打赌,您正在刷新数据,然后对其进行更改,以便下次刷新显示更新后的数据.
I suspect strongly that your problem is in your UI layer, because nothing will ''temporarily remove'' values from your DB. So, I expect that you need to look at your order of execution, I bet you are refreshing your data, then changing it, so the next refresh, shows the updated data.


这篇关于通过V C#2008在Access 2007中未记录记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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