如何从C#.net中的表单插入数据 [英] how to insert data from from form in c#.net

查看:82
本文介绍了如何从C#.net中的表单插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,这是我的程序,现在我要插入,保存,删除数据

hey this is my program now i want to insert, save ,delete the data

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;
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("user id=sa; password=123;database=work");
            string cmdstr = "select * from emp";
            SqlDataAdapter da = new SqlDataAdapter(cmdstr, con);
            DataSet ds = new DataSet();
            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)
        {
           
        }
    }
}


我如何插入数据,请帮帮我


how can i insert the data please help me

推荐答案

我们不做作业:它是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,您可能会发现它并不像您想的那么困难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


这篇关于如何从C#.net中的表单插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆