标题:
MyQQ修改个人资料的源代码
[打印本页]
作者:
qingqing3721
时间:
2011-12-7 03:15
标题:
MyQQ修改个人资料的源代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace MyQQ { public partial class FrmApply : Form { public FrmApply() { InitializeComponent(); } private void gbZhuce_Enter(object sender, EventArgs e) { } int MyQQNum; /// /// 单击注册按钮时数据插入事件 /// /// /// private void btnZhuCe_Click(object sender, EventArgs e) { int StarId = -1; int BooldType = -1; // 调用办法(取得被选中的星座Id) StarId = getStarId(); BooldType = GetBloodTypeId(); // string Sex = rdoMan.Checked ? (string)"男"
string)"女"; string sql = string.Format("insert into Users (NickName,Name,Age,Sex,StarId,BloodTypeId,LoginPwd) values('{0}','{1}',{2},'{3}',{4},{5},'{6}') ", txtName.Text, txtRName.Text, Convert.ToInt32(txtAge.Text), Sex, StarId, BooldType, txtPwd.Text); SqlCommand cmd = new SqlCommand(sql,DBHelper.conn); DBHelper.conn.Open(); int result = cmd.ExecuteNonQuery(); if(result==1) { sql = "select @@Identity from Users"; ; cmd.CommandText = sql; MyQQNum = Convert.ToInt32(cmd.ExecuteScalar()); string message = string.Format("注册成功!你的MyQQ号码是{0}",MyQQNum); MessageBox.Show(message,"注册成功",MessageBoxButtons.OK,MessageBoxIcon.
奥朵灯具水晶灯
Information); } MainForm mainForm = new MainForm(); mainForm.Visible = true; } /// /// 自定义办法 取得被选中的星座Id /// /// /// private int getStarId() { int StarId = -1; string sql = string.Format("select Id from Star Where Star = '{0}'", cboStar.Text); try { SqlCommand command = new SqlCommand(sql, DBHelper.conn); DBHelper.conn.Open(); StarId = Convert.ToInt32(command.ExecuteScalar()); } catch (Exception) { MessageBox.Show("数据库连接异常!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } finally { DBHelper.conn.Close(); } return StarId; } /// /// 自定义办法 加载星座到cboStar中 /// private void GetStar() { int BloodTypeId = GetBloodTypeId(); string sql = string.Format("select Star from Star "); try { DBHelper.conn.Open(); SqlCommand cmd = new SqlCommand(sql, DBHelper.conn); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { cboStar.Items.Add(dataReader[0].ToString()); } dataReader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DBHelper.conn.Close(); } } /// /// 自定义办法 取得被选中的血型Id /// /// /// private int GetBloodTypeId() { int BooldType = -1; string sql = string.Format("select Id from BloodType Where BloodType= '{0}'", cboBooldType.Text); try { SqlCommand cmd = new SqlCommand(sql, DBHelper.conn); DBHelper.conn.Open(); BooldType = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show("数据库连接异常!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } finally { DBHelper.conn.Close(); } return BooldType; } /// /// 自定义办法 加载血型到cboBooldType中 /// private void GetBloodType() { string sql = string.Format("select BloodType from BloodType"); try { DBHelper.conn.Open(); SqlCommand cmd = new SqlCommand(sql, DBHelper.conn); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { cboBooldType.Items.Add(dataReader[0].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show("连接数据库异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { DBHelper.conn.Close(); } } /// /// 加载数据将 星座 血型 进行加载 /// /// /// private void FrmApply_Load(object sender, EventArgs e) { GetStar(); GetBloodType(); } private void btnQuXiao_Click(object sender, EventArgs e) { } } }
欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/)
Powered by Discuz! 6.0.0