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

C#2010编的数据库系统的界面 两个异常求解 编译器异常CS1061和CS0103

2012-12-17 
C#2010编的数据库系统的界面 两个错误求解 编译器错误CS1061和CS0103using Systemusing System.Collectio

C#2010编的数据库系统的界面 两个错误求解 编译器错误CS1061和CS0103
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;
using System.Data.SqlClient;
namespace 航空机票预订管理系统
{
    public partial class login : Form
    {
        public static bool canlog = false;
        public string struser = "";
        public int UType = 0;
        private DataTable ds = new DataTable();
        private DataRow myrow;
        private string sendstrsql = "SELECT * FROM 员工";
        //查用户表语句
        public login()
        {
            InitializeComponent();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            LinkDatabase link = new LinkDatabase();
            this.ds = link.dsresult(sendstrsql);
            for (int i = 0; i < ds.Rows.Count; i++)
            {
                this.myrow = ds.Rows[i];
                if (myrow[0].ToString().Trim() == this.txt_ID.Text.ToString().Trim() && myrow[1].ToString().Trim() == this.txt_pw.Text.ToString().Trim())
                {
                    canlog = true;
                    struser = myrow[0].ToString().Trim();
                    UType = Convert.ToInt32(myrow[2]);
                    this.Close();
                    return;
                }
            }
            MessageBox.Show("您输入的用户名或密码不正确!");
            return;
        }

        private void btn_cancel_Click(object sender, EventArgs e)


        {
            canlog = false;
            this.Close();
        }
    }
}
----------------------------------------------以上是登录时的代码这部分没有问题

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 Flight : Form
    {
        public Flight()
        {
            InitializeComponent();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            string sendstrsql = "SELECT 航班号 FROM 航班 AND 航班号 LIKE '%" + selPno.Text + "%'";
            DataTable dt1 = link.dsresult(sendstrsql);
            dataGridView1.DataSource = dt1.DefaultView;
        }
        private bool checkEmpty()
        {
            bool result = true;
            if (txt_addTno.Text.Trim() == string.Empty)
                result = false;
            else if (txt_addParrive.Text.Trim() == string.Empty)
                result = false;
            else if (txt_addPleave.Text.Trim() == string.Empty)
                result = false;
            else if (txt_addPtime.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('" + txt_addTno.Text + "','" + txt_addParrive.Text + "','" + txt_addPleave.Text + "','" + txt_addPtime.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 button2_Click(object sender, EventArgs e)
        {
            try
            {
                String sendstrsql = "DELETE FROM 航班 WHERE 航班号=" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCel1.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)
        {
            this.Close();
            return;
        }
    }
}
---------这部分是航班管理的代码 
错误1.编译器错误CS1061是“System.Windows.Forms.DataGridView”不包含“CurrentCel1”的定义,并且找不到可接受类型为“System.Windows.Forms.DataGridView”的第一个参数的扩展方法“CurrentCel1”(是否缺少 using 指令或程序集引用?)
错误2.编译器错误 CS0103 上下文不存在link
求解!!!谢谢!!!
[最优解释]
你的代码是扫描的?
CurrentCel1
=>
CurrentCell
是字母l不是1。

link这个变量只能在定义的范围内有效,别处是不能用的。
[其他解释]

引用:
你的代码是扫描的?
CurrentCel1
=>
CurrentCell
是字母l不是1。



link这个变量只能在定义的范围内有效,别处是不能用的。


 没太懂!!!那如果我定义一个命名空间关于link的呢?!怎么定义呢 link是连接数据库的意思?!嗯代码是我敲的嘿嘿~打错啦
[其他解释]
目测,你加上个LinkDatabase link = new LinkDatabase();试试看。
[其他解释]
引用:
目测,你加上个LinkDatabase link = new LinkDatabase();试试看。

哈哈哈哈可以了谢谢!!!!!不过又有个新的问题就是   
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);
            }
        }
这个部分又有这个错误是什么意思?“int”不包含“dataGridView1”的定义,并且找不到可接受类型为“int”的第一个参数的扩展方法“dataGridView1”(是否缺少 using 指令或程序集引用?)
[其他解释]
2.dataGridView1
=>
2, dataGridView1

另外你的sql也有问题,把"AND 座位号=" 修改成 " OR 座位号=" 看看。

代码错的太多了,唉。
[其他解释]
引用:
2.dataGridView1
=>
2, dataGridView1

另外你的sql也有问题,把"AND 座位号=" 修改成 " OR 座位号=" 看看。

代码错的太多了,唉。

不不不 我的那个机票是表的名字 座位号只是里面的一个属性
我都用的中文
那个的意思是主键是航班号和座位号,都是机票这个表里的属性,这样用AND也不对么

热点排行