Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert new records into the database

    Hi, currently I am doing a web application project using 3-tier formating to do out the project. In the grid view is displayed with data retrieved from the database and at the footer there is a row of empty fields for the user to insert records into the database and when user clicks on Add New, a new row of empty fields will be populated below.

    The database.cs and stored procedure is used to stored the data into the database.
    This is the database.cs code:
    public bool Insert_ItemRecords(string itemID, string itemName, string itemDesc)
    {

    SqlCommand cmd_ItemList = new SqlCommand(); cmd_ItemList.CommandText = "[VRM].[INSERT_ItemRecords]"; cmd_ItemList.CommandType = CommandType.StoredProcedure; cmd_ItemList.Parameters.Clear();
    SqlParameter sqlParaItemID = new SqlParameter("@itemID", SqlDbType.VarChar, 10);
    sqlParaItemID.Value = itemID;
    cmd_ItemList.Parameters.Add(sqlParaItemID);
    SqlParameter sqlParaItemName = new SqlParameter("@itemName", SqlDbType.VarChar, 100);
    sqlParaItemName.Value = itemName;
    cmd_ItemList.Parameters.Add(sqlParaItemName);
    SqlParameter sqlParaItemDesc = new SqlParameter("@itemDesc", SqlDbType.VarChar, 1000);
    sqlParaItemDesc.Value = fileName;
    cmd_ItemList.Parameters.Add(sqlParaItemDesc);
    return executeNotQuery(cmd_ItemList); }


    This is the stored procedure code:
    ALTER PROCEDURE [OS].[INSERT_ITEMRecords] @itemID varchar(10),@itemName varchar(100),@itemDesc varchar(1000) ASINSERT INTO OS.Items (itemID, itemName, itemDesc)VALUES (@itemID, @itemName, @itemDesc)

    I am not sure of how to code out for the business logic?
    I code this in business logic but its wrong as the error states the Insert method could not be found:
    protected void gvCriticalTerms_RowCommand(object sender, GridViewCommandEventArgs e)
    if (e.CommandName.Equals("AddNew"))
    {
    TextBox txtItemID = (TextBox)gvItems.FooterRow.FindControl("txtItemID");
    TextBox txtItemName = (TextBox)gvItems.FooterRow.FindControl("txtItemName");
    TextBox txtItemDesc = (TextBox)gvItems.FooterRow.FindControl("txtItemDesc");

    os.Insert_ItemsRecords(txtItemID .Text, txtItemName.Text, txtItemDesc.Text);
    BindGrid1();
    }
    }


    Thanks

  • #2
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you insert normal Sql Statement ?
    stirng str="INSERT INTO t1(id,name) values(1,'abc')

    Then

    Use ....Command for Insert Data


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •