private void button2_Click(object sender, EventArgs e) { if (radioButton1.Checked) { textBox1.Enabled = true; textBox2.Enabled = true; textBox3.Enabled = true; textBox4.Enabled = true; textBox5.Enabled = false; settypestring = "update info set [value]='1' where id='1'"; setconinfostr = string.Format("update dbconfig set host='{0}',db='{1}',username='******',userpass='******' where id='1'", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), textBox4.Text.Trim()); } if (radioButton2.Checked) { textBox1.Enabled = true; textBox2.Enabled = true; textBox3.Enabled = false; textBox4.Enabled = false; textBox5.Enabled = false; settypestring = "update info set [value]='2' where id='1'"; setconinfostr = string.Format("update dbconfig set host='{0}',db='{1}' where id='2'", textBox1.Text.Trim(), textBox2.Text.Trim()); } if (radioButton3.Checked) { textBox1.Enabled = false; textBox2.Enabled = false; textBox3.Enabled = false; textBox4.Enabled = false; textBox5.Enabled = true; settypestring = "update info set [value]='3' where id='1'"; setconinfostr = string.Format("update dbconfig set custom='{0}' where id='3'", textBox5.Text.Trim()); } testconstr = this.getconstr(); SqlConnection con = new SqlConnection(testconstr); try { con.Open(); if (con.State == ConnectionState.Open) { con.Close(); if (ss.setlocalinfo(setconinfostr)) { if (ss.setlocalinfo(settypestring)) { MessageBox.Show("设置成功!"); } } else { MessageBox.Show("设置失败!"); } } else { MessageBox.Show("当前连接设置存在问题,不能保存!"); } } catch (SqlException se) { MessageBox.Show("当前连接设置存在问题,不能保存!失败原因:" + se.Message + ",不能保存!"); } }