private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { string sno = (comboBox2.Text.ToString()).Split('-')[0]; SqlConnection Conn = op.conn();//到sqlsever的连接 Conn.Open(); string gradeString = "select grade from score where sno = '" + sno + "'"; SqlCommand cmd = new SqlCommand(gradeString, Conn); textBox1.Text = cmd.ExecuteScalar().ToString();//C# 如何把数据库的查询语句查出来的值赋给某一变量 /* if (!Regex.IsMatch(textBox1.Text, "^[1-9]")) * { * MessageBox.Show("输入正确的学分!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); * return; * } * else * { * string sno = (comboBox2.Text.ToString()).Split('-')[0]; * string cno = (selectCourse.Text.ToString().Split('-'))[0]; * string sql = "insert into score(sno,cno,grade) values('" + sno + " ','" + cno + " '," + textBox1.Text.ToString() + ")"; * //insert into course(cno, cname, ccategory, credit) * if (op.OPSQL(sql)) * { * ClearText(); * MessageBox.Show("新建成功!"); * } * else * { * MessageBox.Show("创建失败!"); * } * }*/ }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string cno = (comboBox1.Text.ToString()).Split('-')[0]; SqlConnection Conn = op.conn();//到sqlsever的连接 Conn.Open(); string strCmd = "select credit from course where cno = '" + cno + "'"; SqlCommand cmd = new SqlCommand(strCmd, Conn); textBox1.Text = cmd.ExecuteScalar().ToString();//C# 如何把数据库的查询语句查出来的值赋给某一变量 textBox1.ReadOnly = true; }