标题:为什么我的数据不能更新呢?(高手帮忙)
只看楼主
purewqk
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-10-24
 问题点数:0 回复次数:3 
为什么我的数据不能更新呢?(高手帮忙)
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 图书馆管理
{
    public partial class DataAdd : Form
    {
        //private Container components;
        private DataSet myDataSet;
       // private BindingManagerBase myBind;
        public DataAdd()
        {
            GetConnected();
            InitializeComponent();
        }
        public void GetConnected()
        {
            try
            {
                string constr = "workstation id=;packet size=8000;integrated security=SSPI;data source=.;pe" +
                 "rsist security info=False;initial catalog=图书馆管理系统";
                SqlConnection cn1 = new SqlConnection(constr);
                string sq1 = "SELECT * from Storage";
                myDataSet = new DataSet();
                cn1.Open();
                SqlDataAdapter myCommand = new SqlDataAdapter(sq1, cn1);
                myCommand.Fill(myDataSet, "Storage");
                cn1.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("连接错误!" + e.ToString(), "错误");
            }
        }
        protected void saveclick(object sender, System.EventArgs e)
        {
            try {
                if (T_BookNo.Text != "" && T_BookName.Text != "" && T_WriName.Text != "" && T_PubHouse.Text != "" && T_SavePlace.Text != "" && T_State.Text != "")
                {
                    string constr = "workstation id=;packet size=8000;integrated security=SSPI;data source=.;pe" +
                    "rsist security info=False;initial catalog=图书馆管理系统";
                    SqlConnection cn1 = new SqlConnection(constr);
                    cn1.Open();
                    string strInsert=" UPDATE  Storage Set BookName=T_BookName.Text,WriName=T_WriName.Text,PubHouse=T_PubHouse.Text,SavePlace=T_SavePlace.Text,State=T_State.Text,WHERE BookNo= ";
                    strInsert +=T_BookNo.Text;
                    SqlCommand inst=new SqlCommand( strInsert, cn1);
                    inst.ExecuteNonQuery();
                    cn1.Close();
                }
                else
                {
                  MessageBox.Show("必须填满所有字段值!","错误!") ;
                }
               }
                catch (Exception ed)
                {
                    MessageBox.Show(("修改数据记录发生") + ed.ToString(),"错误!") ;
                }
           }
        }
}

[[italic] 本帖最后由 purewqk 于 2007-12-26 21:49 编辑 [/italic]]

图书管理.jpg (11.1 KB)
搜索更多相关主题的帖子: using System 数据 private 
2007-12-26 21:45
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
得分:0 
update语句有错
这样写:'"+T_BookName.Text+"'
要引起来

不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2007-12-26 22:30
loveling
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-10-19
得分:0 
update语句有错
UPDATE  Storage Set' '""+T_BookName.Text " ', ' " + + " '

我的邮箱:loveyoulizhao@
2007-12-27 16:15
hxhfg
Rank: 1
等 级:新手上路
帖 子:284
专家分:0
注 册:2006-4-18
得分:0 
k
k

2007-12-27 19:51



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




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

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