标题:调试界面数据可以更新,但不能更改数据库里的数据,请大神指点
只看楼主
haining6699
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:97
专家分:734
注 册:2014-12-3
结帖率:100%
 问题点数:0 回复次数:3 
调试界面数据可以更新,但不能更改数据库里的数据,请大神指点
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace c1
{
    public partial class Form1 : Form
    {
        private SqlConnection con;
        private BindingManagerBase dh;
        private SqlCommandBuilder dc;
        private SqlDataAdapter dx;
        private DataSet dq;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string strcon = "server=localhost;uid=sa;pwd=123456;database=Test";
           // using (SqlConnection con = new SqlConnection())
           // {
                con = new SqlConnection();
                con.ConnectionString = strcon;
                con.Open();
                dx = new SqlDataAdapter("select * from dwxx", con);
                dc = new SqlCommandBuilder(dx);
                dq = new DataSet();
                dx.Fill(dq, "dw");
                Binding b1 = new Binding("Text", dq, "dw.单位编号");
                textBox1.DataBindings.Add(b1);
                Binding b2 = new Binding("Text", dq, "dw.单位名称");
                textBox2.DataBindings.Add(b2);
                dataGridView1.DataSource = dq.Tables["dw"];
                dh=this.BindingContext[dq,"dw"];
                comboBox1.DataSource=dq.Tables["dw"];
                comboBox1.DisplayMember = "单位名称";
           // }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dh.Position = 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (dh.Position < dh.Count - 1) dh.Position++;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dh.Position > 0) dh.Position--;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            dh.Position = dh.Count - 1;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            dx.Update(dq, "dw");
        }
    }
}

搜索更多相关主题的帖子: 数据库 color 
2016-05-14 19:39
haining6699
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:97
专家分:734
注 册:2014-12-3
得分:0 
就没有大神可以指点下吗?真心不知道为什么啊

2016-05-14 20:31
haining6699
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:97
专家分:734
注 册:2014-12-3
得分:0 
路过的大神,伸一下你的手吧
2016-05-15 08:51
haining6699
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:97
专家分:734
注 册:2014-12-3
得分:0 
呼叫版主,难道这个帖子应该发在SQL区???
2016-05-15 09:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464825-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021529 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved