标题:新人求助 下面是代码和错误提示图片
只看楼主
syh1968yh
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-6-23
结帖率:0
已结贴  问题点数:20 回复次数:9 
新人求助 下面是代码和错误提示图片
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 通讯录窗体
{
    public partial class Form主界面 : Form
    {
        public Form主界面()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form添加信息 from = new Form添加信息();
            from.Show();
        }

        private void Form主界面_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void Form主界面_Load(object sender, EventArgs e)
        {
            txtContant.Clear();
            sqlDataAdapter1.Fill(txtContant, "address");

        }
   
        private void btnUpd_Click_1(object sender, EventArgs e)
        {
            try
            {

                if (btnUpd.Text == "修改记录")
                {
                    dgvAddress.ReadOnly = false;
                    btnUpd.Text = "保存修改";
                    btnAdd.Enabled = false;
                    btnDel.Enabled = false;
                }
                else
                {
                    sqlDataAdapter1.Update(txtContant, "Address");
                    btnUpd.Text = "修改记录";
                    dgvAddress.ReadOnly = true;
                    btnAdd.Enabled = true;
                    btnDel.Enabled = true;
                }
            }

            catch (Exception Exc)
            {
                MessageBox.Show(Exc.Message);
            }
        }

        private void btnPwd_Click_1(object sender, EventArgs e)
        {
            this.Hide();
            Form修改密码 form = new Form修改密码();
            form.Show();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {

                DialogResult result = MessageBox.Show("真的要删除当前记录吗?", "删除记录", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    int n = dgvAddress.CurrentRow.Index;
                    DataTable myTab = new DataTable();
                    myTab = txtContant.Tables["address"];
                    DataRow myRow = myTab.Rows[n];
                    string xh = myRow[0].ToString();
                    int i = int.Parse(xh);
                    string connectionString = "Data Source=.;database=addressbook;Integrated Security=True";
                    SqlConnection myCon = new SqlConnection();
                    myCon.ConnectionString = connectionString;
                    SqlCommand myCom = myCon.CreateCommand();
                     = "delete  address where 序号=" + i + "";
                    myCon.Open();
                    myCom.ExecuteNonQuery();
                    myCom.Dispose();
                    myCon.Close();
                    txtContant.Clear();
                    sqlDataAdapter1.Fill(txtContant, "address");
                    MessageBox.Show("删除成功");
                }
            }

            catch (Exception Exc)
            {
                MessageBox.Show(Exc.Message);
            }

        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {

            txtContant.Clear();
            sqlDataAdapter1.Fill(txtContant, "address");
            btnAdd.Enabled = true;
            btnDel.Enabled = true;
            btnUpd.Text = "修改记录";
            dgvAddress.ReadOnly = true;
        }

        private void btnExit_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form主界面_Load_1(object sender, EventArgs e)
        {
            txtContant.Clear();
            sqlDataAdapter1.Fill(txtContant, "address");
        }

        private void btnALL_Click(object sender, EventArgs e)
        {
            dgvAddress.DataSource = txtContant;
            dgvAddress.DataMember = "address";
            txtContant.Clear();
            sqlDataAdapter1.Fill(txtContant, "address");

        }

        private void btnselect_Click(object sender, EventArgs e)
        {
            string connectionString = "Data Source=.;database=addressbook;Integrated Security=True";
            SqlConnection myCon = new SqlConnection();
            myCon.ConnectionString = connectionString;
            SqlCommand myCom = myCon.CreateCommand();
            SqlDataAdapter myAdpter = new SqlDataAdapter();
            DataSet mySet = new DataSet();
            int n;
            switch (cbxClass.SelectedIndex)
            {
                case 0: = "select * from address where 姓名='" + txtContant.Text + "'";
                    myAdpter.SelectCommand = myCom;
                    n = myAdpter.Fill(mySet, "address");
                    dgvAddress.DataSource = mySet;
                    dgvAddress.DataMember = "address";

                    if (n == 0)
                    {
                        MessageBox.Show("未找到相应信息", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtContant.Clear();
                        sqlDataAdapter1.Fill(txtContant, "address");
                    }
                    break;
                case 1: = "select * from address where 电话='" + txtContant.Text + "'";
                    myAdpter.SelectCommand = myCom;
                    n = myAdpter.Fill(mySet, "address");
                    dgvAddress.DataSource = mySet;
                    dgvAddress.DataMember = "address";
                    if (n == 0)
                    {
                        MessageBox.Show("未找到相应信息", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtContant.Clear();
                        sqlDataAdapter1.Fill(txtContant, "address");
                    }
                    break;
                case 2: = "select * from address where QQ号='" + txtContant.Text + "'";
                    myAdpter.SelectCommand = myCom;
                    n = myAdpter.Fill(mySet, "address");
                    dgvAddress.DataSource = mySet;
                    dgvAddress.DataMember = "address";
                    if (n == 0)
                    {
                        MessageBox.Show("未找到相应信息", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtContant.Clear();
                        sqlDataAdapter1.Fill(txtContant, "address");
                    }
                    break;
            }

        }

        private void cbxClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxClass.SelectedIndex == -1)
            {
                txtContant.ReadOnly = true;
            }
            else
            {
                txtContant.ReadOnly = false;
            }

        }

      }
搜索更多相关主题的帖子: private public 通讯录 图片 
2015-06-23 11:46
syh1968yh
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-6-23
得分:0 
大神快到碗里来
2015-06-23 12:04
Maick
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:32
帖 子:251
专家分:1314
注 册:2012-9-21
得分:7 
人家都提示不存在了..你在你窗体中有本事找出来啊
2015-06-23 13:18
w2009w
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:190
专家分:542
注 册:2015-4-20
得分:7 
太复杂了 代码太长 还是自己在一行行检查吧
2015-06-23 14:13
Maick
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:32
帖 子:251
专家分:1314
注 册:2012-9-21
得分:0 
sqlDataAdapter1 你在哪里声明了 ????
2015-06-23 14:54
smart0721
Rank: 6Rank: 6
等 级:侠之大者
威 望:4
帖 子:106
专家分:468
注 册:2012-2-10
得分:7 
好多问题 首先 sqlDataAdapter1没声明
还有txtContant这个是什么? 一个textbox控件怎么能那样用?
sqlDataAdapter1.Fill(txtContant, "address"); 这里的txtContant应该是一个dataset 你写错了 估计应该是你定义的那个mySet 而且这个也应定义为全局变量



[ 本帖最后由 smart0721 于 2015-6-28 12:35 编辑 ]
2015-06-28 12:27
外挂是什么瓜
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-4-1
得分:0 
sqlDataAdapter1 没有申明

r=a(1-sinθ)
2015-07-11 00:15
ggx7061131
Rank: 2
等 级:论坛游民
威 望:1
帖 子:21
专家分:12
注 册:2012-7-5
得分:0 
窗体上的控件(要么有控件了,name的属性被改了)与上面的代码根本不匹配
2015-07-11 17:20
lililioo01
Rank: 2
等 级:新手上路
威 望:3
帖 子:9
专家分:3
注 册:2015-7-10
得分:0 
F5调试不就O了吗
2015-07-12 19:37
lililioo01
Rank: 2
等 级:新手上路
威 望:3
帖 子:9
专家分:3
注 册:2015-7-10
得分:0 
<a>F5调试下</a>
2015-07-12 19:38



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




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

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