1234567890
2016-12-06 16:56
92 查看
private void Form3_Load(object sender, EventArgs e) { BinGrade(); } public bool BinGrade() { MySchool.DBHelper s = new MySchool.DBHelper(); try { string sql = "SELECT * FROM [MySchool].[dbo].[Grade]"; s.OpenConnection(); SqlCommand command = new SqlCommand(sql, s.Connection); SqlDataReader myReader = command.ExecuteReader(); while (myReader.Read()) { string gradeName = myReader["GradeName"].ToString(); comboBox1.Items.Add(gradeName); //comboBox1.Items.Add(gradeName); } myReader.Close(); return true; } catch (Exception e) { MessageBox.Show(e.Message,"提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } finally { s.CloseConnection(); } } public bool InsertStudent() { bool success = false; string pwd = this.textBox2.Text.Trim(); string name=this.textBox4.Text.Trim(); int gender = 0; if (this.rbtnFemale.Checked) { gender = 0; } else { gender = 1; } int genderId = (int)gender; string grade = this.comboBox1.Text.Trim(); string phone = this.textBox5.Text.Trim(); string address = this.textBox6.Text.Trim(); DateTime date = this.dateTimePicker1.Value; string email = this.textBox7.Text.Trim(); string birthday = string.Format("{0}-{1}-{2}", date.Year, date.Month, date.Day); MySchool.DBHelper s = new MySchool.DBHelper(); try { string sqlName = String.Format("select gradeId from grade where gradeName='{0}'", grade); SqlCommand command = new SqlCommand(sqlName, s.Connection); s.OpenConnection(); int gradeId = (int)command.ExecuteScalar(); StringBuilder sql = new StringBuilder(); sql.AppendLine("INNERT INTO [Student] ([LoginPwd],[StudentName],[Gender],[GradeId],[Phone],[Address],[Birthday] ,[Email]) "); sql.AppendLine("VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", pwd, name, genderId, gradeId, phone, address, birthday, email); command = new SqlCommand(sql.ToString, s.Connection); s.OpenConnection(); int result = command.ExecuteNonQuery(); if (result == 1) { string sqlNo = "SELECT @@IDENTITY FROM [Student]"; command.CommandText = sqlNo; int studentNo = Convert.ToInt32(command.ExecuteScalar()); this.textBox1.Text = studentNo.ToString(); 4000 success = true; } } catch (Exception) { success = false; } finally { s.CloseConnection(); } }
相关文章推荐
- 如何把1234567890变成1,234,567,890?
- 将1234567890转换成1,234,567,890每3位用逗号隔开的形式(百度)
- 写一个方法,将一个字符串(1234567890)转换成(1,234,567,890)每三个一组用逗号隔开()
- 将一个字符串(1234567890)转换成(1,234,567,890)每三个一组用逗号隔开
- google笔试题:计算1-N(N=1234567890)中1出现的次数。
- 写一个方法,将一个字符串(1234567890)转换成(1,234,567,890)每三个一组用逗号隔开。 用2种方法。
- 时间:1234567890
- 时间:1234567890
- 时间1234567890
- 将1234567890转换成1,234,567,890 每3位用逗号隔开的形式
- UNIX时间抵达1234567890
- 将1234567890----->1,234,567,890
- 有趣的 UNIX 时间: 1234567890
- javascript格式化数字问题(1234567890 --> 1,234,567,890)
- Unix Lovers To Party Like It’s 1234567890
- php题目将1234567890转化成1,234,567,890每3位用,隔开
- 将1234567890转换成1,234,567,890 每3位用逗号隔开的形式
- 将1234567890转换成1,234,567,890 每3位用逗号隔开的形式 PHP千分位
- 1234567890
- javascript用正则表达式把1234567890替换为abcdefghij