当前位置:编程学习 > C#/ASP.NET >>

麻烦各位帮忙调下程序 ,我做的程序无法对数据库进行修改 谢谢!

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 Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {// TODO: 这行代码将数据加载到表“通讯录DataSet.Contact”中。您可以根据需要移动或删除它。
            this.contactTableAdapter.Fill(this.通讯录DataSet.Contact);
              SqlConnection con = new SqlConnection("server=;database=通讯录;integrated security =true");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Contact_Command  ", con);
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataSet ds = new DataSet();
             sda.Fill(ds, "Contact");
            dataGridView1.DataSource = ds.Tables[0];
            

             

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {   
            
           
            txtName.Text=dataGridView1.SelectedCells[0].Value.ToString();
            txtBirthday.Text=dataGridView1.SelectedCells[1].Value.ToString();
            txtPhone.Text=dataGridView1.SelectedCells[2].Value.ToString();
            txtMail.Text=dataGridView1.SelectedCells[3].Value.ToString();
            txtAddress.Text=dataGridView1.SelectedCells[4].Value.ToString();
            

        }

        private void button1_Click(object sender, EventArgs e)
        {
          
              DataSet ds = new DataSet();
              DataTable dt = ds.Tables["Contact"];
              SqlDataAdapter sda = new SqlDataAdapter();
            sda.FillSchema(dt,SchemaType.Mapped);
             DataRow dr = dt.Rows.Find(txtName.Text);
             dr["姓名"] = txtName.Text.Trim();
             dr["生日"] =  this .txtBirthday.Text.Trim();
             dr["电话"] = this.txtPhone.Text.Trim();
             dr["邮箱"] = this.txtMail.Text.Trim();
             dr["地址"] = this.txtAddress.Text.Trim();
           

            SqlCommandBuilder cmdbuilder=new SqlCommandBuilder(sda);
         sda.Update(dt);
        }
    }
}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,