当前位置:编程学习 > C#/ASP.NET >>

C#2010 SQL Server做机票预订系统两个问题

问题1:

点添加或者删除显示成功,但是数据库的表并没有更新,为什么?!代码哪里有问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 航空机票预订管理系统
{
    public partial class ticket : Form
    {
        LinkDatabase link = new LinkDatabase();
        public ticket()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {

            string sendstrsql = "SELECT 航班号,座位号,机票类型 FROM 机票 WHERE 航班号='" + sel_Pno.Text + "' AND 座位号='" + sel_Pseat.Text + "'";
            DataTable dt1 = link.dsresult(sendstrsql);
            dataGridView2.DataSource= dt1.DefaultView;
         
        }
        private bool checkEmpty()
        {
            bool result = true;
            if (add_Pseat.Text.Trim() == string.Empty)
                result = false;
            else if (add_Tno.Text.Trim() == string.Empty)
                result = false;
            else if (add_Ttype.Text.Trim() == string.Empty)
                result = false;
            return result;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkEmpty() == true)
            {
                try
                {
                    string sendstrsql = "INSERT INTO 机票 VALUES('" + add_Pseat.Text + "','" + add_Tno + "','" + add_Ttype + "')";
                    link.updatedb(sendstrsql);
                    MessageBox.Show("成功添加数据");
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else MessageBox.Show("输入不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string sendstrsql = "DELETE FROM 机票 WHERE 座位号=" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "AND 座位号=" + Convert.ToString(dataGridView1[2,dataGridView1.CurrentCell.RowIndex].Value).Trim() + "";
                link.updatedb(sendstrsql);
                MessageBox.Show("记录删除成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ticket_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“book_ticketDataSet3.机票”中。您可以根据需要移动或删除它。
            this.机票TableAdapter.Fill(this.book_ticketDataSet3.机票);

        }
    }
}
问题2:
不小心删除了book_ticketDataSet5.xsd和book_ticketDataSet6.xsd发生错误:未能找到类型或命名空间名称“book_ticketDataSet6”(是否缺少 using 指令或程序集引用?)但是程序仍然可以成功运行,请问怎么找回?!!
--------------------编程问答-------------------- 问题1:添加删除成功后需要重新绑定数据源 除非你用SqlDataAdapter来Update是不需要重新绑定的
问题2:不清楚 --------------------编程问答-------------------- 但是程序仍然可以成功运行 
断点吧! 这些小错误都可以自己解决的
我就进来看看 --------------------编程问答-------------------- 为什么不用存储过程解决呢?这样会不会容易出问题?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,