码迷,mamicode.com
首页 > 数据库 > 详细

数据库修改

时间:2015-01-26 11:40:06      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConnSqlForm
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private string _Xuehao;
private string _Name;
private string _Sex;
private string _Birthday;
public Form2(string xuehao,string name,string sex,string birthday)
{
InitializeComponent();
_Xuehao = xuehao;
_Name = name;
_Sex = sex;
_Birthday = birthday;
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=snewdata;user=sa;pwd=");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "update student set name=@name,sex=@sex,birthday=@birthday where xuehao=@xuehao";
cmd.Parameters.Clear();

cmd.Parameters.Add("@xuehao", txtxuehao.Text.Trim());
cmd.Parameters.Add("@name", txtname.Text.Trim());
if (rbtnan.Checked)
{
cmd.Parameters.Add("@sex", "男");
}
else
{
cmd.Parameters.Add("@sex", "女");
}
cmd.Parameters.Add("@birthday", dateTimePicker1.Value);

conn.Open();
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("修改成功,受影响行数为:" + count.ToString());
}
else
{
MessageBox.Show("修改失败!");
}
conn.Close();
}

private void Form2_Load(object sender, EventArgs e)
{
txtxuehao.Text = _Xuehao;
txtname.Text = _Name;
if (_Sex == "男")
{
rbtnan.Checked = true;
}
else
{
rbtnv.Checked = true;
}
dateTimePicker1.Value = DateTime.Parse(_Birthday);
}
}
}

数据库修改

标签:

原文地址:http://www.cnblogs.com/liuyuwen900326/p/4249803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!