数据库 WPF 应用程序出现问题,无法添加任何内容

发布于 2024-12-02 04:19:34 字数 2072 浏览 0 评论 0原文

我试图向我的数据库表添加新行,这表明应用程序 WPF 中一切进展顺利,当我关闭应用程序时,数据库没有更改(数据库中未添加新记录)我尝试使用数据适配器,所以这是我使用的类和

  DD.cs
   namespace WpfApplication2
  {
   class DD
  {

    private Database1DataSetTableAdapters.Table1TableAdapter _cpuAdapter = null;

    protected Database1DataSetTableAdapters.Table1TableAdapter Adapter
    {
        get
        {
            if (_cpuAdapter == null)
                _cpuAdapter = new Database1DataSetTableAdapters.Table1TableAdapter();

            return _cpuAdapter;
        }

    }





      [System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool AddCPU(string Naslov, string Avtor, string Lokacija, int Broj, string 

Zabeleska 后面的代码,字符串 Izdava) {

        Database1DataSet.Table1DataTable cpus = new Database1DataSet.Table1DataTable();
        Database1DataSet.Table1Row cpu = cpus.NewTable1Row();

        cpu.Naslov = Naslov;
        if (Naslov == null) cpu.SetNaslovNull();
        else cpu.Naslov = Naslov;
        if (Avtor == null) cpu.SetAvtorNull();
        else cpu.Avtor = Avtor;
        if (Zabeleska == null) cpu.SetZabeleskaNull();
        else cpu.Zabeleska = Zabeleska;
        if (Izdava == null) cpu.SetIzdavaNull();
        else cpu.Izdava = Izdava;
        if (Broj == null) cpu.SetBrojNull();
        else cpu.Broj = Broj;
        if (Lokacija == null) cpu.SetLokacijaNull();
        else cpu.Lokacija = Lokacija;


        cpus.AddTable1Row(cpu);
        int rowsAffected = Adapter.Update(cpus);

        // Return true if precisely one row was inserted, otherwise false
        return rowsAffected == 1;
    }

 HERE IS THE CODE BEHIND

 it's an event on button click
   string n, a, z,t,l;
        int b;
        l = txtLokacija.Text;
        t = txtBroj.Text;
        b = Convert.ToInt32(t);
        n = txtNaslov.Text;
        a = txtAvtor.Text;
        z = txtZabeleska.Text;
        t = "NONE";
        txtZabeleska.Clear();
        DD obj1=new DD();
        obj1.AddCPU(n,a,l,b,z,t);

I was trying to add new row to my database table and it seams that everything is going well in the application WPF and when i close the application the database has not changed(new record was not added in the database ) I tried to use dataadapters so here is my class that i use and the code behing

  DD.cs
   namespace WpfApplication2
  {
   class DD
  {

    private Database1DataSetTableAdapters.Table1TableAdapter _cpuAdapter = null;

    protected Database1DataSetTableAdapters.Table1TableAdapter Adapter
    {
        get
        {
            if (_cpuAdapter == null)
                _cpuAdapter = new Database1DataSetTableAdapters.Table1TableAdapter();

            return _cpuAdapter;
        }

    }





      [System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool AddCPU(string Naslov, string Avtor, string Lokacija, int Broj, string 

Zabeleska, string Izdava)
{

        Database1DataSet.Table1DataTable cpus = new Database1DataSet.Table1DataTable();
        Database1DataSet.Table1Row cpu = cpus.NewTable1Row();

        cpu.Naslov = Naslov;
        if (Naslov == null) cpu.SetNaslovNull();
        else cpu.Naslov = Naslov;
        if (Avtor == null) cpu.SetAvtorNull();
        else cpu.Avtor = Avtor;
        if (Zabeleska == null) cpu.SetZabeleskaNull();
        else cpu.Zabeleska = Zabeleska;
        if (Izdava == null) cpu.SetIzdavaNull();
        else cpu.Izdava = Izdava;
        if (Broj == null) cpu.SetBrojNull();
        else cpu.Broj = Broj;
        if (Lokacija == null) cpu.SetLokacijaNull();
        else cpu.Lokacija = Lokacija;


        cpus.AddTable1Row(cpu);
        int rowsAffected = Adapter.Update(cpus);

        // Return true if precisely one row was inserted, otherwise false
        return rowsAffected == 1;
    }

 HERE IS THE CODE BEHIND

 it's an event on button click
   string n, a, z,t,l;
        int b;
        l = txtLokacija.Text;
        t = txtBroj.Text;
        b = Convert.ToInt32(t);
        n = txtNaslov.Text;
        a = txtAvtor.Text;
        z = txtZabeleska.Text;
        t = "NONE";
        txtZabeleska.Clear();
        DD obj1=new DD();
        obj1.AddCPU(n,a,l,b,z,t);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舂唻埖巳落 2024-12-09 04:19:34

我发现它......当我完成应用程序并发布时,似乎一切正常,数据库工作正常......我重新启动了电脑和新添加的记录

I found IT....when i finished the application and published then it seemed everything ok the database was working properly..i;ve restarted the PC and the newly added record

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文