| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1500 人关注过本帖
标题:新人求助 下面是代码和错误提示图片
取消只看楼主 加入收藏
syh1968yh
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-6-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
新人求助 下面是代码和错误提示图片
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
快速回复:新人求助 下面是代码和错误提示图片
数据加载中...
 
   



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

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