VS208中,在WINforM中添加一个TEXTBOX和一个BUTTON,当点击BUTTON时,将TEXTBOX中的数据添加到数据库中。

[复制链接]
查看11 | 回复3 | 2011-3-14 10:29:21 | 显示全部楼层 |阅读模式
假设button的id为button1,textbox的id为textbox1,如果你不分层的话,可以用下边的代码直接实现
protected void Button1_Click(object sender, EventArgs e)
{
string value = this.TextBox1.Text;
SqlConnection conn = new SqlConnection("server=.;database=数据库名;uid=你的登录名;pwd=你的登陆密码");
SqlCommand cmd = new SqlCommand("insert into 数据库...
回复

使用道具 举报

千问 | 2011-3-14 10:29:21 | 显示全部楼层
private int addQuestion() {
int result = 0;
string sql = string.Format(
"INSERT INTO Question values('{0}','{1}',{2},'{3}','{4}','{5}','{...
回复

使用道具 举报

千问 | 2011-3-14 10:29:21 | 显示全部楼层
button事件中string value=this.Textbox1.Text;//执行数据库操作// insert table value('"+value+"')...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行