Becky Bloomwood

Becky Bloomwood

  • NA
  • 119
  • 239.9k

Inserting records rfrom gridview

Feb 14 2011 10:35 AM
Hi, I am using gridview footer to insert records into the database. I need to insert startDate(datetime datatype), endDate(datatype),amount(float)as well as other varchar data.
This is my database.cs:

 //method to create contracts
public bool Insert_ContractRecords(string contractID, string empName, SqlDateTime startDate, SqlDateTime endDate, float amount, string vendorbrn, string name, string products, string rfpRef, string projectTitle, string alert)
{
SqlCommand cmd_ContractList = new SqlCommand();

cmd_ContractList.CommandText = "[VRM].[INSERT_ContractRecords]";
cmd_ContractList.CommandType = CommandType.StoredProcedure;
cmd_ContractList.Parameters.Clear();


SqlParameter sqlParaContractID = new SqlParameter("@contractID", SqlDbType.VarChar, 10);//ContractID
sqlParaContractID.Value = contractID;
cmd_ContractList.Parameters.Add(sqlParaContractID);

SqlParameter sqlParaEmpName = new SqlParameter("@empName", SqlDbType.VarChar, 140);//Owner Name aka Employee Name
sqlParaEmpName.Value = formatWildCard(empName);
cmd_ContractList.Parameters.Add(sqlParaEmpName);


SqlParameter sqlParaStartDate = new SqlParameter("@startDate", SqlDbType.DateTime); //Contract Start DATE
sqlParaStartDate.Value = startDate;
cmd_ContractList.Parameters.Add(sqlParaStartDate);

SqlParameter sqlParaEndDate = new SqlParameter("@endDate", SqlDbType.DateTime); //Contract End date
sqlParaEndDate.Value = endDate;
cmd_ContractList.Parameters.Add(sqlParaEndDate);


SqlParameter sqlParaAmount = new SqlParameter("@amount", SqlDbType.Float); //amount
sqlParaAmount.Value = amount;
cmd_ContractList.Parameters.Add(sqlParaAmount);


SqlParameter sqlParaVendorBRN = new SqlParameter("@vendorbrn", SqlDbType.VarChar, 10);//Vendor BRN
sqlParaVendorBRN.Value = vendorbrn;
cmd_ContractList.Parameters.Add(sqlParaVendorBRN);

SqlParameter sqlParaVendorName = new SqlParameter("@name", SqlDbType.VarChar, 140);//Vendor Name
sqlParaVendorName.Value = name;
cmd_ContractList.Parameters.Add(sqlParaVendorName);

SqlParameter sqlParaProducts = new SqlParameter("@products", SqlDbType.VarChar, 1000);//Products/Services provided by vendor
sqlParaProducts.Value = products;
cmd_ContractList.Parameters.Add(sqlParaProducts);


SqlParameter sqlParaRFPRef = new SqlParameter("@rfpRef", SqlDbType.VarChar, 50);//RFPRef
sqlParaRFPRef.Value = rfpRef;
cmd_ContractList.Parameters.Add(sqlParaRFPRef);

SqlParameter sqlParaProjectTitle = new SqlParameter("@projectTitle", SqlDbType.VarChar, 50);//Project Title
sqlParaProjectTitle.Value = projectTitle;
cmd_ContractList.Parameters.Add(sqlParaProjectTitle);


SqlParameter sqlParaAlert = new SqlParameter("@alert", SqlDbType.VarChar, 1);//Alert
sqlParaAlert.Value = alert;
cmd_ContractList.Parameters.Add(sqlParaAlert);


return executeNotQuery(cmd_ContractList);


}

This is my stored procedure:
 

ALTER PROCEDURE [VRM].[INSERT_ContractRecords]
(

@contractID varchar(10),
@empName varchar(140),
@startDate datetime,
@endDate datetime,
@amount float,
@vendorbrn varchar(10),
@name varchar(140),
@products varchar(1000),
@rfpRef varchar(50),
@projectTitle varchar(50),
@alert varchar(1),
@templateID varchar(10)

)




AS

BEGIN

INSERT INTO VRM.ContractManagement VALUES( @contractID , @empName,@startDate, @endDate,@amount,@vendorbrn,@name,@products,@rfpRef,@projectTitle,@alert,@templateID)

END


This is my business logic:
 

protected void gvContract_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{




TextBox txtContractID = (TextBox)gvContract.FooterRow.FindControl("txtContractID");
TextBox txtEmpName = (TextBox)gvContract.FooterRow.FindControl("ttxtEmpName");
TextBox txtStartDate = (TextBox)gvContract.FooterRow.FindControl("txtstartDate");
TextBox txtEndDate = (TextBox)gvContract.FooterRow.FindControl("txtEndDate");
TextBox txtAmount = (TextBox)gvContract.FooterRow.FindControl("txtEndDate");
TextBox txtVendorBRN = (TextBox)gvContract.FooterRow.FindControl("txtVendorBRN");
TextBox txtName = (TextBox)gvContract.FooterRow.FindControl("txtName ");
TextBox txtProducts = (TextBox)gvContract.FooterRow.FindControl("txtProducts ");
TextBox txtRef = (TextBox)gvContract.FooterRow.FindControl("txtRef");
TextBox txtProj = (TextBox)gvContract.FooterRow.FindControl("txtProj");
TextBox txtAlert = (TextBox)gvContract.FooterRow.FindControl("txtProj");



vrmdb.Insert_ContractRecords(txtContractID.Text, txtEmpName.Text, txtStartDate.Text, txtEndDate.Text, txtAmount.Text, txtVendorBRN.Text, txtName.Text, txtProducts.Text, txtRef.Text, txtProj.Text, txtAlert.Text);



BindGrid(true);
Response.Redirect("ContractThreeGridView.aspx");

}
}


However there is an error indicating:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'com.vrm.database.vrm_database.Insert_ContractRecords(string, string, System.Data.SqlTypes.SqlDateTime, System.Data.SqlTypes.SqlDateTime, float, string, string, string, string, string, string)' has some invalid arguments

Source Error:



Line 283:
Line 284:
Line 285: vrmdb.Insert_ContractRecords(txtContractID.Text, txtEmpName.Text, txtStartDate.Text, txtEndDate.Text, txtAmount.Text, txtVendorBRN.Text, txtName.Text, txtProducts.Text, txtRef.Text, txtProj.Text, txtAlert.Text);
Line 286:
Line 287:


Source File: c:\Users\Maggie\Desktop\Peggie\Peggie\Deployment Source\Phase 1\Deployment 25 Nov for StarHub\VS Projects Source\VRM_WebSite\app\vrm\ContractManagement.aspx.cs Line: 285


May I know how to resolve it?Thanks!




Answers (7)