Click here to Skip to main content
15,063,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
                OleDbCommandBuilder cmd = new OleDbCommandBuilder(dataAdapter);
                ds = new DataSet();
            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


public DataSet binsert(adddelBookProps p)

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


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.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;
        dataAdapter.Update(ds, "books");
Updated 14-May-11 12:01pm
Wonde Tadesse 14-May-11 17:29pm
Please properly format your question.

public DataSet dal_insert(adddelBookProps p)

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

return ds;

Not completed. What is the parameter do here ?
Keith Barrow 14-May-11 18:03pm
Please wrap your code in pre tags (see my edit) it makes your code readable. What do you mean by "There are some issues"?
codegeekalpha 14-May-11 18:08pm
dataAdapter.update does not exits in the current context.. this is the erro
lw@zi 15-May-11 2:42am
What is the error?

1 solution

Couple of things here, as well as those mentioned already

* dataSet dal_insert()
does a select, not an insert

* in the insertRecord(String query) routine
I think OleDb* works the same as Sql* calls and in Sql* calls you need to create a a SqlCommand object for the adaptor before the SqlCommandBuilder class

<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 />


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900