View Full Version : Insert new records into the database

02-01-2011, 07:44 AM
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;
SqlParameter sqlParaItemName = new SqlParameter("@itemName", SqlDbType.VarChar, 100);
sqlParaItemName.Value = itemName;
SqlParameter sqlParaItemDesc = new SqlParameter("@itemDesc", SqlDbType.VarChar, 1000);
sqlParaItemDesc.Value = fileName;
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);


02-24-2011, 09:46 AM
Can you insert normal Sql Statement ?
stirng str="INSERT INTO t1(id,name) values(1,'abc')


Use ....Command for Insert Data