using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 航空机票预订管理系统
{
    public partial class passenger : Form
    {
        public passenger()
        {
            InitializeComponent();
        }
         private void selbtn_Click(object sender, EventArgs e)
        {
            sendstrsql="SELECT 旅客.身份证号 FROM 旅客";
                DataTable dt1=link.dsresult(sendstrsql);
            dataGridView1.DataSource=dt1.DefaultView;
        }
        private bool checkEmpty()//判断四个textbox是否均有输入信息
        {
            bool result = true;
            if (txt_addCname.Text.Trim() == string.Empty)
                result = false;
            else if (txt_addCsex.Text.Trim() == string.Empty)
                result = false;
            else if (txt_addCno.Text.Trim() == string.Empty)
                result = false;
            else if (txt_addCtele.Text.Trim() == string.Empty)
                result = false;
            return result;
        }
        private void btn_add_Click(object sender, EventArgs e)
        {
            if(checkEmpty()==true)//当四个textbox均输入时,才进行插入操作
            {try{
                sendstrsql="INSERT INTO passenger VALUES('"+ txt_addCname.Text+"','"+ txt_addCsex.Text+"','"+ txt_addCno.Text+"','"+ txt_addCtele.Text+"')";
                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 button4_Click(object sender, EventArgs e)
        {
            this.Close();
            return;
        }
    }
}
错误提示我:当前上下文不存在名称sendstrsql和link咋办???

解决方案 »

  1.   

    问题有两点:
    1、sendstrsql没有定义是因为你没有声明这个变量就直接使用了,解决办法是在sendstrsql前面加上string 
    也就是说效果是string sendstrsql,后面的代码保持不变就可以解决了2、link 这个对象应该是你没有引入自定义的命名空间,所以程序中找不到这个对象,也因此无法调用相应的方法
      

  2.   

    好的THANKS:)表示第一次编数据库大作业~
      

  3.   

    我也sorry,这个貌似是别人自定义命名空间里面的,我没有千里眼所以