protected void btnEditor_Click(object sender, EventArgs e)
        {           
            //读取数据库连接字符串
            string conn = ConfigurationSettings.AppSettings["conn"];            //创建数据库连接
            myconn = new OleDbConnection(conn);            //创建修改章信息的SQL语句
            string sql = "insesrt into 表 (字段1,字段2)";            //创建OleDbCommand
            OleDbCommand mycmd = new OleDbCommand(sql, myconn);            //打开数据库连接
            myconn.Open();            //执行插入新文章的SQL语句
            mycmd.ExecuteNonQuery();            //关闭数据库连接
            myconn.Close();
        }

解决方案 »

  1.   


    using System.Data.SqlClient;namespace InsertData
    {
        class calss1
           {
                public void insertData()
                {
                   String strConn = "Source Data =.;uid=sa;pwd=sa;Initial Catalog=(数据库名)";          //构建数据库连接字符串
                   String sqlText = "Insert into 表名(字段1,字段2) values('字段1值','" + textbox1.Text + "')";  //构建插入数据库的Sql语句
                   SqlConnection sqlcon = new SqlConnection(strConn);                                  //声明数据库连接对象
                   SqlCommand    sqlcom = new Sql(sqlText,sqlcon);                                     //执行数据库操作的对象
                   try
                   {
                       if(sqlcon.State == ConnectionState.Clos)
                        {
                         edsqlcon.Open();                                                              //如果没有打开数据库连接则打开数据库
                           }
                        sqlcom.ExecuteNonQuery();                                                      //执行数据库操作
                   }
                   catch (Exception err)
                   {
                       MessageBox.Show("错误: "+ err.Message)                
                   }
                   finally
                   {
                      if (sqlcon.State != ConnectionState.Closed)
                      {
                         sqlcon.Close();                                     //关闭数据库连接
                      }
                   }
                }
           }
    }
      

  2.   

    更改一下:
    try 

        if(sqlcon.State   ==   ConnectionState.Closed) 
         { 
           sqlcon.Open();                         //如果没有打开数据库连接则打开数据库 
          } 
        sqlcom.ExecuteNonQuery();                //执行数据库操作 

      

  3.   

    不行,提示将截断字符串或二进制数据.语句已停止
    下面是我写的不过只能查如一句你看下://string connectionString= "Integrated Security=SSPI;Initial Catalog=修改的;Data Source=(local);";
                    //string str = textBox2.Text;
                    //System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connectionString);
                    //con.Open();
                    //string insertCommand = "insert into biao(Sname) values(@str)";
                    //System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(insertCommand,con);
                    //cmd.Parameters.Add("@str",System.Data.SqlDbType.Char,100).Value =str;
                    //cmd.ExecuteNonQuery();
                    //con.Close();
    例如:个人   取得   工资   、   薪金   所得   应当   如何   缴纳   个人所得税                                       个人   取得   的   工资   、   薪金   所得   ,   是   指   个人   因   任职   或者   受雇   而   取得   的   工资   、   薪金   、   奖金   、   年终   加薪   、   劳动   分红   、   津贴   、   补贴   以及   与   任职   或   受雇   有关   的   其他   所得   。                       工资   、   薪金   所得   项目   税率   表       (   请   参考   个人所得   税法   )  (是已经分好的)  怎么能让他们每个都是一个记录呢
    ?
      

  4.   

    楼主看下这段吧,也是ado.net的数据库连接。通常的查询和更改操作应该足够了
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data.SqlClient;namespace System.Data.ProcedureCommand
    {
        /**/
        /// <summary>
        /// 数据库简单sql使用类
        /// 封装了一个SqlCommand
        /// 
        /// </summary>
        /// 
        public class Yj_smplSql
        {
            //全局sqlConnection对象
            SqlConnection sqlConnection;        //全局SqlCommand对象
            //SqlCommand _sqlCmd;        //全局SqlDataAdapter对象
            //SqlDataAdapter _sqladapter;        public Yj_smplSql(String connStr)
            {
                sqlConnection = new SqlConnection(connStr);
            }        public DataSet query(String queryStr)
            {
                DataSet ds = null;
                try
                {
                    ds = new DataSet();
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(queryStr, sqlConnection);
                    // Fill the DataSet. 
                    sqlDataAdapter.Fill(ds);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("query错误....." + ex.Message);
                    throw new Exception(ex.ToString());
                }
                finally
                {
                    sqlConnection.Close();
                }
                return ds;
            }        public int modify(string queryStr)
            {
                int count = -1;   //影响的条数
                try
                {
                    sqlConnection.Open();
                    SqlCommand sqlCommand = new SqlCommand(queryStr, sqlConnection);
                    count = sqlCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("modify错误....." + ex.Message);
                    throw new Exception(ex.ToString());
                }
                finally
                {
                    sqlConnection.Close();
                }
                return count;
            }
            public object ExecuteScalar(string sqlCmd)
            {
                SqlCommand cmd = new SqlCommand(sqlCmd, sqlConnection);
                sqlConnection.Open();
                object ret = cmd.ExecuteScalar();
                sqlConnection.Close();
                return ret;
            }    }
    }