首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#2012联接SQL server2008设计机票预订系统

2012-12-17 
C#2012连接SQL server2008设计机票预订系统using Systemusing System.Collections.Genericusing System.

C#2012连接SQL server2008设计机票预订系统
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();
        }

查询之后,可以出来表格但是并未能显示数据!!!请问怎样修改代码?!!!我已经在dataGridView控件的DataSource属性里添加了数据库表。。。
[最优解释]
 string sendstrsql = "SELECT 航班号,座位号,机票类型 FROM 机票 WHERE 航班号='"+ sel_Pno.Text +"' AND 座位号='"+ sel_Pseat.Text +"'";

[其他解释]
把sql语句放入LIST集合中,然后就是直接将list赋给datagridview
[其他解释]

引用:
把sql语句放入LIST集合中,然后就是直接将list赋给datagridview

list集合?!请问是什么 在sql里面么
[其他解释]
用存储过程或参数化处理比较好 楼主的这个会被注入
------其他解决方案--------------------


引用:
string sendstrsql = "SELECT 航班号,座位号,机票类型 FROM 机票 WHERE 航班号='"+ sel_Pno.Text +"' AND 座位号='"+ sel_Pseat.Text +"'";


3楼的正解

热点排行