从c#.net中的数据库插入数据 [英] to insert data from database in c#.net
本文介绍了从c#.net中的数据库插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
namespace empinformation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dt;
int currenrec = 0;
int totalrec = 0;
static SqlConnection con = new SqlConnection("user id=sa; password=123;database=work");
static SqlDataAdapter da = new SqlDataAdapter("select * from emp", con);
DataSet ds = new DataSet();
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
private void button1_Click(object sender, EventArgs e)
{
da.Fill(ds, "emp");
dt = ds.Tables["emp"];
currenrec = 0;
totalrec = dt.Rows.Count;
FillControls();
btnext.Enabled = true;
btprev.Enabled = true;
}
private void FillControls()
{
txtemp.Text = dt.Rows[currenrec]["empno"].ToString();
txtename.Text = dt.Rows[currenrec]["ename"].ToString();
txtjob.Text = dt.Rows[currenrec]["job"].ToString();
txtsal.Text = dt.Rows[currenrec]["sal"].ToString();
txthrd.Text = dt.Rows[currenrec]["hiredate"].ToString();
txtcom.Text = dt.Rows[currenrec]["comm"].ToString();
txtdept.Text = dt.Rows[currenrec]["deptno"].ToString();
}
private void btnext_Click(object sender, EventArgs e)
{
currenrec += 1;
if (currenrec >= totalrec)
{
currenrec = 0;
}
FillControls();
}
private void btprev_Click(object sender, EventArgs e)
{
currenrec -= 1;
if (currenrec <= totalrec)
{
currenrec = totalrec-1;
}
FillControls();
}
private void btnew_Click(object sender, EventArgs e)
{
cmd.GetInsertCommand();
}
private void btsve_Click(object sender, EventArgs e)
{
cmd.GetUpdateCommand();
}
private void btdel_Click(object sender, EventArgs e)
{
cmd.GetDeleteCommand();
}
}
}
推荐答案
Hm.您提供了一些代码.问题出在哪儿?你的问题是什么?
Hm. You provided some code. Where is the problem? What''s your question?
这篇关于从c#.net中的数据库插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文