对应数据表T_BAS_STUDENT字段:vc_name,vc_age,vc_sex,vc_degree,d_birth,n_totalscore,vc_re;主窗体load的时候就把表里的记录查询出来显示,点击新增按钮就弹出添加记录的form,里面有对应字段的文本框和datetimepicker;删除在主窗体进行,点中需要删除的记录,点击删除即可;查询也在主窗体,有相应的查询文本框,按姓名和分数查询;修改在新窗体进行,点击需要修改的记录,新窗体对应文本框显示对应的记录的值,然后修改,点击修改按钮即可。C#WinFormsqlserver2008
解决方案 »
- 非泛型集合ArrayList和泛型集合List,运行时间问题
- xml 默认命名空间
- ultraGrid 数值型字段排序问题
- wince Hook 使用的问题
- C#如何给MDI主窗口添加背景
- asp.net 客户端打印小票的问题 100分等
- 用VS.Net 2003 自带打包工具,增加自定义用户界面,在安装时响应用户的选择。可是用Condition属性,不起作用。
- 在C#中如何获取中文字符串的首字母
- SqlCommand oCmd;运行时出错,是怎么回事
- 无论你是IT行业里从事技术的、销售的,大家把所有的资源都统一起来,寻找机会,共同创业~!请加入这个QQ群~!
- cookie的归属
- graphics.DrawString 对齐有关问题
-->单步调试,不是F5就可以了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class frmAdd : Form
{
public frmAdd()
{
InitializeComponent();
} string name;
string age;
string sex;
string degree;
string birth;
string re;
int score; private void frmAdd_Load(object sender, EventArgs e)
{
string sqlconn = "Data Source=.;database=test;User ID=sa;Password=123456";
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
string sql = "select * from T_BAS_DICTIONARY where vc_dic_sortid = 1 order by vc_dic_number asc";
SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet();
da.Fill(ds);
this.cbSex.DataSource = ds.Tables[0];
this.cbSex.DisplayMember = "vc_dic_name";
this.cbSex.ValueMember = "n_dic_id";
conn.Close();
} private void btnClear_Click(object sender, EventArgs e)
{
clear();
txtName.Focus();
} public void clear()
{
txtAge.Text = "";
txtDegree.Text = "";
txtName.Text = "";
txtScore.Text = "";
cbSex.Text = "";
dtpBirth.Text = "";
txtRe.Text = "";
} private void txtScore_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsNumber(e.KeyChar) == false)
{
e.Handled = true;
}
else
{
e.Handled = false;
}
} private void btnExit_Click(object sender, EventArgs e)
{
this.Hide();
frmList List = new frmList();
List.Refresh();
} public void assign()
{
name = txtName.Text.Trim();
age = txtAge.Text.Trim();
sex = cbSex.Text.Trim();
degree = txtDegree.Text.Trim();
birth = dtpBirth.Value.ToShortDateString();
re = txtRe.Text.Trim();
score = Int32.Parse(txtScore.Text.Trim());
} private void btnAdd_Click(object sender, EventArgs e)
{
if (txtName.Text == "" || txtAge.Text == "" || cbSex.Text == "" || txtDegree.Text == "" || txtScore.Text == "" || txtRe.Text == "")
{
MessageBox.Show("有一个或多个数据未填!");
}
else
{
string strconn = "Data Source=.;database=test;User ID=sa;Password=123456";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
assign();
string sql = string.Format("insert into T_BAS_STUDENT(vc_name,vc_age,vc_sex,vc_degree,d_birth,n_totalscore,vc_re)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", name, age, sex, degree, birth, score, re); SqlDataAdapter da = new SqlDataAdapter(sql, conn);
MessageBox.Show("插入成功!");
}
}
}
}
//删了这句
SqlDataAdapter da = new SqlDataAdapter(sql, conn);//改为
SqlCommand cmd=new SqlCommand(sql,conn);
int n=cmd.ExecuteNonQuery();
if(n>0) MessageBox.Show("插入成功!");
conn.Close();