本文介绍了在3层中使用数据集和dataadapter插入数据...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个3层应用程序,用于使用数据适配器和数据集插入数据.有一些问题.

检查其中是否不包含所有代码属性层.
databaselayerwork,dbcon类

I am making a 3 tier app for inserting data using data adpater and data set. There are some issues.

check all code properties layer is not included in it.
databaselayerwork, dbcon class

public class dbcon

{
 public DataSet insertRecord(String query)
        {
            DataSet ds = null;
            try
            {
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
                OleDbCommandBuilder cmd = new OleDbCommandBuilder(dataAdapter);
                ds = new DataSet();
                dataAdapter.Fill(ds);
            }
            catch (Exception ex)
            {
                // MessageBox.Show(ex.Message);
            }
            return ds;






调用该类的数据库层工作:-







databse layer work calling that class :-


 public DataSet dal_insert(adddelBookProps p)
        {

            string query = "select * from books ";
            DataSet ds = obj.insertRecord(query);

            return ds;
}






业务层

工作:-






Business layer

work:-

public DataSet binsert(adddelBookProps p)
        {

            DataSet ds = new DataSet();
            //OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
            ds = t.dal_insert(p);
            return ds;

        }






主窗体Insrt按钮的工作方式







Main Form Insrt button work


protected void btnadd_Click(object sender, EventArgs e)
    {

        adddelBookProps p = new adddelBookProps();
        admenRegBll obj = new admenRegBll();
        p.Bookno = booknotxt.Text;
        p.Isbn=isbntxt.Text;
        p.Booktitle=booktitletxt.Text;
        p.Author=authortxt.Text;
        p.Quantity=quantitytxt.Text;
        p.Price=pricetxt.Text;
        p.Published = pytxt.Text;

        DataSet ds = obj.binsert(p);
        //OleDbDataAdapter dataAdapter = obj.binsert;
        DataTable dt = ds.Tables["Table"];
        dt.TableName = "books";

        // Insert the Data
        DataRow dr = ds.Tables["books"].NewRow();
        dr["bookno"] = p.Bookno;
        dr["isbn"] = p.Isbn;
        dr["booktitle"] = p.Booktitle;
        dr["author"] = p.Author;
        dr["quantity"] = p.Quantity;
        dr["price"] = p.Price;
        dr["pubyear"] = p.Published;
        ds.Tables["books"].Rows.Add(dr);
        //oDS.Tables["Orders"].Rows.Add(oOrderRow);

        dataAdapter.Update(ds, "books");
        //MessageBox.Show("inserted");

推荐答案

<br />
                SqlConnection conn = new SqlConnection(TheConnectionString);<br />
                SqlCommand cmd = new SqlCommand("select * from inventory");<br />
                cmd.Connection = conn; <br />
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);<br />
                SqlCommandBuilder bld = new SqlCommandBuilder(adapter );<br />
                // just for reference below <br />
                SqlCommand cmdUpdate = bld.GetUpdateCommand();<br />
                SqlCommand cmdInsert = bld.GetInsertCommand();<br />



这篇关于在3层中使用数据集和dataadapter插入数据...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:35