标题:TextBox中的数据绑定并更新数据库问题
只看楼主
sunny007sun
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-5-8
 问题点数:0 回复次数:2 
TextBox中的数据绑定并更新数据库问题
TextBox中的数据绑定并更新数据库问题

一windows窗体中有多个textbox都和数据库中某表进行绑定,能显示数据,但不能更新
代码如下:


            // TODO: 这行代码将数据加载到表“dianZiBingLiDataSet8.basy”中。您可以根据需要移动或移除它。
            this.basyTableAdapter.Fill(this.dianZiBingLiDataSet8.basy);
            // TODO: 这行代码将数据加载到表“dianZiBingLiDataSet8.BingRen”中。您可以根据需要移动或移除它。
            this.bingRenTableAdapter.Fill(this.dianZiBingLiDataSet8.BingRen);            

以下为保存按钮中的代码:
 if (this.dianZiBingLiDataSet8.basy.Rows.Count==0)
            {
                DataRow row = this.dianZiBingLiDataSet8.basy.NewRow();
                row["住院号"] = textBox4.Text;
                row["zyzd"] = textBox74.Text;
                this.dianZiBingLiDataSet8.basy.Rows.Add(row);  
            }
            else
            {
                foreach(DataRow row in this.dianZiBingLiDataSet8.basy.Rows)
                {
                    row.BeginEdit();
                    row["住院号"] = textBox4.Text;
                    row["zyzd"] = textBox74.Text;
                    row.EndEdit();
                }
            }
             try
            {
                this.bingRenTableAdapter.Update(this.dianZiBingLiDataSet8, "basy");
                this.dianZiBingLiDataSet8.basy.Clear();
                this.bingRenTableAdapter.Fill(this.dianZiBingLiDataSet8,"basy");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

报The method or operation is not implemented的异常,数据库不更新。


请大家帮忙看看是那出问题了,谢谢!!!
搜索更多相关主题的帖子: TextBox 数据库 绑定 
2010-05-31 13:24
sunny007sun
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-5-8
得分:0 
怎么没有帮忙啊~~~~~
2010-06-01 18:44
末小柒
Rank: 2
等 级:论坛游民
帖 子:6
专家分:40
注 册:2010-6-11
得分:0 
绑定
string strcon="workstation id=.;packet size=4096;integrated security=SSPI;data source=.;persist security info=False;initial catalog=zhb";
            SqlConnection conn= new SqlConnection(strcon);
            conn.Open();
            string sql="select * from employ where name='"+tbname.Text+"'";
            SqlCommand com=new SqlCommand(sql,conn);
            SqlDataReader dr=com.ExecuteReader();
            while(dr.Read())
            {
                tbid.Text=dr[0].ToString();
                tbname.Text=dr[1].ToString();
                tbdp.Text=dr[2].ToString();
                tbage.Text=dr[3].ToString();
                tbsex.Text=dr[4].ToString();
                tbed.Text=dr[5].ToString();
                tbtt.Text=dr[6].ToString();
            }
            dr.Close();
            conn.Close();
更新问题使用update更新语句不就可以了么?
try            
string strcon ="连接数据库字符串";
    SqlConnection conn= new SqlConnection(strcon);
                conn.Open();
                string sql="update employ set name='"+tbname.Text+"',department='"+tbdp.Text+"',age='"+tbage.Text+"',sex='"+tbsex.Text+"',education='"+tbed.Text+"',title='"+tbtt.Text+"' where name='"+str_name+"'";
                SqlCommand com=new SqlCommand(sql,conn);
                int i=com.ExecuteNonQuery();
                if(i>0)
                {
                    MessageBox.Show("修改成功!");
                    Form1_Load(null,null);

                }
                else
                {
                    MessageBox.Show("修改失败!");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
2010-06-12 16:31



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




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

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