这是一个实现数据库中“菜单”表格更新的c#语句,但是我是新手看不懂这些代码,求大家帮忙详细解释一下每句话的意思,谢谢了!using System.Data.SqlClient;
using System.Configuration;namespace WindowsFormsApplication2
{
    public partial class Form9 : Form
    {        private DataSet ds;
        private BindingSource bs;
        public Form9()
        {
            InitializeComponent();
            ds = new DataSet();
            bs = new BindingSource();
        }
        private void ChuShiHua()
        {
            string ssql = "select * from 菜单";
            SqlDataAdapter ad = new SqlDataAdapter(ssql, "Data Source=PC2011102615VKX;Initial Catalog=sunny饭店;Integrated Security=True");            ds.Clear();
            ad.Fill(ds, "菜单");
            bs.DataSource = ds;
            bs.DataMember = "菜单";            bindingNavigator1.BindingSource = bs;
            dataGridView1.DataSource = bs;
                  }
        private void button1_Click(object sender, EventArgs e)
        {
            string ssql = "insert into 菜单(菜名,菜型,单价,) values('" + textBox1.Text + "','" + comboBox3.Text + "'," + textBox4.Text + ")";
            SqlConnection cn = new SqlConnection("Data Source=PC2011102615VKX;Initial Catalog=sunny饭店;Integrated Security=True");            cn.Open();            SqlCommand cmd = new SqlCommand(ssql, cn);
            cmd.ExecuteNonQuery();
            cn.Close();
        }        private void Form9_Load(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);           ChuShiHua();
            textBox1.DataBindings.Add("Text", bs, "菜名", false, System.Windows.Forms.DataSourceUpdateMode.Never);
            textBox1.DataBindings.DefaultDataSourceUpdateMode = System.Windows.Forms.DataSourceUpdateMode.Never;
            comboBox3.DataBindings.Add("Text", bs, "菜型", false, System.Windows.Forms.DataSourceUpdateMode.Never);
            textBox4.DataBindings.Add("Text", bs, "单价", false, System.Windows.Forms.DataSourceUpdateMode.Never);
           
           
        }
                    
      
    }
}

解决方案 »

  1.   

    多看看MSDN
    http://book.51cto.com/art/200908/148584.htm
      

  2.   


      private void button1_Click(object sender, EventArgs e)
      {
      string ssql = "insert into 菜单(菜名,菜型,单价,) values('" + textBox1.Text + "','" + comboBox3.Text + "'," + textBox4.Text + ")";//语句
      SqlConnection cn = new SqlConnection("Data Source=PC2011102615VKX;Initial Catalog=sunny饭店;Integrated Security=True");//连接  cn.Open();  SqlCommand cmd = new SqlCommand(ssql, cn);
      cmd.ExecuteNonQuery();//执行
      cn.Close();
      }