SqlDataAdapter 更新实例

来源:互联网 发布:抽号软件在线 编辑:程序博客网 时间:2024/06/06 12:39

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication17
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection ("Server=localhost\\SQLEXPRESS;Database=开销;User ID=sa;Password=110;Trusted_Connection=False");
            con.Open ();
            DataSet ds =new DataSet ();
            SqlDataAdapter da = new SqlDataAdapter("select top 0 * from test1", con);
            da.Fill(ds, "test1");
            for (int i = 1; i < 40; i++)
            {
                DataRow dr = ds.Tables["test1"].NewRow();
                dr["id"] = i;
                dr["name"] = Convert.ToChar(i);
                ds.Tables["test1"].Rows.Add(dr);
                Console.WriteLine(Convert .ToChar(i));
               
             }
                         SqlCommandBuilder cb = new SqlCommandBuilder(da);
           
            da.Update(ds.Tables["test1"]);
            MessageBox.Show("ok");

        }
    }
}

0 0
原创粉丝点击