http://www.cnblogs.com/hzuIT/archive/2007/05/15/688900.html
private void button1_Click(object sender, EventArgs e) 

//DataTable table = (DataTable)dataGrid1.DataSource; 
//table.Rows[dataGrid1.CurrentRowIndex].Delete(); 
//dataGrid1.DataSource = dataSet1.Tables[0].DefaultView; 
//dataSet1.Tables[0].DefaultView[dataGrid1.CurrentRowIndex].Delete(); //oleDbDataAdapter1.Fill(dataSet1, "tushu"); 
int current = dataGrid1.CurrentCell.RowNumber; 
string tushuma = dataGrid1[current, 0].ToString(); 
string de = "delete* from tushu where 图书码='"+tushuma+"'"; 
OleDbCommand mycommand = new OleDbCommand(de,oleDbConnection1); 
mycommand.CommandText = de; 
//OleDbParameter parm = mycommand.Parameters.Add("@tushuma",OleDbType.VarChar,13,"tushuma"); 
oleDbConnection1.Open(); 
mycommand.ExecuteNonQuery(); 
oleDbConnection1.Close(); }
兄弟,勤快一点儿嘛

解决方案 »

  1.   

    对单个表还是多个表啊!还有是winForm还是webForm!它们的操作可不一样啊!
      

  2.   

    xinghongyang() ( ) 信誉:100  2007-07-28 20:50:59  得分: 0  
     
     
       对单个表还是多个表啊!还有是winForm还是webForm!它们的操作可不一样啊!
      
     
    ------------------------------------------
    winform,对一个表
      

  3.   

    兄弟给你个网址这里保证你能学到好多东西
    http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx
      

  4.   

    kongwei521(蝶恋花雨) ( ) 信誉:100  2007-7-28 22:33:54  得分: 0  
     
     
       
    兄弟给你个网址这里保证你能学到好多东西
    http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx  
     
    ----------------------------
    那个是WEB,我暂时不需要
      

  5.   

    http://msdn2.microsoft.com/zh-cn/library/fbk67b6z(VS.80).aspx#Mtps_DropDownFilterText
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication4
    {
        public partial class Form1 : Form
        {
            private SqlDataAdapter dataAdapter ;
            SqlConnection cn;
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                //dataGridView1.DataSource = bindingSource1;
                string strCn = string.Empty;
                strCn = @"";
                cn = new SqlConnection();
                cn.ConnectionString = strCn;
               
                dataAdapter = this.CreateMessageAdapter();
                //SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);            DataTable result = new DataTable();
                try 
                {
                    cn.Open();
                    dataAdapter.Fill(result);
                    this.dataGridView1.DataSource = result;
                    //bindingSource1.DataSource = result;
                    
                }
                catch (Exception ex) { throw new Exception(ex.Message); }
                finally { cn.Close(); }        }        private void button2_Click(object sender, EventArgs e)
            {
                DataTable result = (DataTable)dataGridView1.DataSource;
                DataTable tableDelete = result.GetChanges(DataRowState.Deleted);
                if (tableDelete != null && tableDelete.Rows.Count > 0)
                {
                    dataAdapter.Update(tableDelete);
                }            DataTable tableInsert = result.GetChanges(DataRowState.Added);
                if (tableInsert != null && tableInsert.Rows.Count > 0)
                {
                    dataAdapter.Update(tableInsert);
                }
                DataTable tableChanged = result.GetChanges(DataRowState.Modified);            ;
                if (tableChanged != null && tableChanged.Rows.Count > 0)
                {
                    dataAdapter.Update(tableChanged);
                }                  }        private SqlDataAdapter CreateMessageAdapter()
            {
                SqlCommand command = null;
                dataAdapter = new SqlDataAdapter();
                command = new SqlCommand("select * from messages", cn);
                dataAdapter.SelectCommand = command;
                
                command = new SqlCommand("update messages set message=@Message where id=@Id", cn);
                command.Parameters.Add(new SqlParameter("@Message", SqlDbType.NVarChar, 140, "Message"));
                SqlParameter parameter = command.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int, 4, "Id"));
                parameter.SourceVersion = DataRowVersion.Original;
                dataAdapter.UpdateCommand = command;                 command = new SqlCommand("insert messages (message) values(@Message)", cn);
                command.Parameters.Add(new SqlParameter("@Message", SqlDbType.NVarChar, 140, "Message"));
                dataAdapter.InsertCommand = command;
                            command = new SqlCommand("delete messages where id=@Id", cn);
                parameter = command.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int, 4, "Id"));
                parameter.SourceVersion = DataRowVersion.Original;            dataAdapter.DeleteCommand = command;
                return dataAdapter;
            }
        }
    }