日期:2014-05-17  浏览次数:20728 次

C#问题。。求高手帮忙看看
 private void button1_Click(object sender, EventArgs e)
        {
            int age = Convert.ToInt32(textBox4 .Text );
            int gonglin = Convert.ToInt32(textBox7.Text);
            String cnno = "Data Source=HP-PC;Initial Catalog=FIRST;Integrated Security=True;Pooling=False";
            SqlConnection connection = new SqlConnection(cnno);
            string sql = string.Format("Insert into Xinxi values('Xno='{0}'','Xname='{1}'','Xsex='{2}'','Xage='{3}'','Xbumen='{4}'','Xzhicheng='{5}'','Xgonglin='{6}'','Xphone='{7}'','Xjiguan='{8}'','Xzhuzhi='{9}'') ", textBox1.Text, textBox2.Text, textBox3.Text, age, textBox5.Text, textBox6.Text, gonglin, textBox8.Text, textBox9.Text, textBox10.Text);

            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);
            //int num = Convert.ToInt32(command.ExecuteScalar());
            int num = (int)command.ExecuteNonQuery();
            try
            {
                if (num > 0)
                {

                    MessageBox.Show("修改成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("原密码错误!");
                }


            }
            catch (Exception ex)
            {

                MessageBox.Show("错误异常" + ex);
            }
            finally
            {
                connection.Close();
            }