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

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

问题描述

我正在学习dotnet的新知识,请任何人帮助我如何插入数据.我已经写了一些代码

hi i am learning new to the dotnet please anyone help me how to insert the data . i have written some code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
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();
       
        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)
        {

            SqlCommand cmd = new SqlCommand();
        }

        private void btsve_Click(object sender, EventArgs e)
        {
          
        }
        private void btdel_Click(object sender, EventArgs e)
        {
            
        }
    }
}

推荐答案

不确定要从发布的代码中问什么.

查看这些内容,以了解如何使用ADO.NET获取数据:
MSDN:ADO.NET [ MSDN:使用ADO.NET访问数据 [ ^ ]
MSDN:DataAdapter参数(ADO.NET) [
Not sure what you wanted to ask from the code posted.

Look at these to learn on how to use ADO.NET to get data:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]
MSDN: DataAdapter Parameters (ADO.NET)[^]


使用:sqlcommand.executenonquery [ SQLCommand.Parameters属性 [
Use: sqlcommand.executenonquery[^]
SQLCommand.Parameters Property[^]


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

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