http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3090|回复: 4

[学生提问] 新手求助 代码和图片

[复制链接]
发表于 2015-6-23 08:43:24 | 显示全部楼层 |阅读模式
1金钱
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 Form主界面 : Form
    {
        public Form主界面()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form添加信息 from = new Form添加信息();
            from.Show();
        }

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

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

        private void btnUpd_Click(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 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();
                    myCom.CommandText = "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 Form主界面_Load(object sender, EventArgs e)
        {
            txtContant.Clear();
            sqlDataAdapter1.Fill(txtContant, "address");
        }

        private void btnCancel_Click(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(object sender, EventArgs e)
        {
            this.Close();
        }

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

        private void btnSelcet_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: myCom.CommandText = "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: myCom.CommandText = "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: myCom.CommandText = "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 btnAll_Click(object sender, EventArgs e)
        {
            dgvAddress.DataSource = txtContant ;
            dgvAddress.DataMember = "address";
            txtContant.Clear();
            sqlDataAdapter1.Fill(txtContant, "address");
        }
    }
}

错误列表

错误列表


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2015-6-23 08:44:38 | 显示全部楼层
坐等大神路过
回复

使用道具 举报

发表于 2015-6-23 09:40:38 | 显示全部楼层
没有引用命名空间吧。引用一下就行了。
回复

使用道具 举报

 楼主| 发表于 2015-6-23 10:21:16 | 显示全部楼层
站长苏飞 发表于 2015-6-23 09:40
没有引用命名空间吧。引用一下就行了。

具体怎么弄啊
回复

使用道具 举报

发表于 2015-6-23 14:07:45 | 显示全部楼层

using 后面是你想要的命名空间。http://www.sufeinet.com/thread-4367-1-1.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-5 18:49

© 2014-2021

快速回复 返回顶部 返回列表