Orion Orion - 3 months ago 25
ASP.NET (C#) Question

No Overload for method which takes 4 arguments

I am trying to update gridview. Here, I have used 3 tier architecture method.

Here is my GridView.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ResllerID"
ForeColor="#333333" GridLines="None" OnRowDeleting="DeleteRecord" EmptyDataText="There are no data records to display."
AllowPaging="True" AllowSorting="True" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Reseller Name" SortExpression="ResellerName">
<EditItemTemplate>
<asp:TextBox ID="ResellerTextBox" runat="server" Text='<%# Bind("ResellerName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ResellerName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile Number" SortExpression="MobileNumber">
<EditItemTemplate>
<asp:TextBox ID="MobileTextBox" runat="server" Text='<%# Bind("MobileNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("MobileNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Reference Number" SortExpression="ReferenceNumber">
<EditItemTemplate>
<asp:TextBox ID="ReferenceTextBox" runat="server" Text='<%# Bind("ReferenceNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ReferenceNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>


Here is my code: I am getting error ResellerBL.UpdateReseller(resellerId, name.Text, mobileNumber.Text, referenceNumber.Text); It says No Overload for method which takes 4 arguments

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataSource = ResellerBL.GetResellers();
GridView1.DataBind();
}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int resellerId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
TextBox name = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
TextBox mobileNumber = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];
TextBox referenceNumber = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];

ResellerBL.UpdateReseller(resellerId, name.Text, mobileNumber.Text, referenceNumber.Text);

GridView1.EditIndex = -1;
GridView1.DataSource = ResellerBL.GetResellers();
GridView1.DataBind();
}


ResellerBL code:

public static void UpdateReseller(Reseller reseller)
{
string query = "UPDATE [Resellers] SET [ResellerName] = @ResellerName, [ReferenceNumber] = @ReferenceNumber WHERE [ResellerID] = @ResellerID";
SqlCommand cmd = new SqlCommand(query);

cmd.Parameters.AddWithValue("@ResellerName", SqlDbType.Text).Value = reseller.ResellerName;
cmd.Parameters.AddWithValue("@MobileNumber", SqlDbType.Text).Value = reseller.MobileNumber;
cmd.Parameters.AddWithValue("@ReferenceNumber", SqlDbType.Text).Value = reseller.ReferenceNumber;

cmd.Parameters.AddWithValue("@ResllerID", SqlDbType.Text).Value = reseller.ResllerID;

DbUtility.UpdateDb(cmd);
}

Answer

You are calling it with four arguments:

ResellerBL.UpdateReseller(resellerId, name.Text, mobileNumber.Text, referenceNumber.Text);

But it only accepts one:

public static void UpdateReseller(Reseller reseller)

Two options are

  1. Create a new reseller object and pass that:

.

var myreseller = New Reseller();
myresller.Id = resellerId;
//etc

ResellerBL.UpdateReseller(myreseller);

OR

  1. Modify the (or add an overloaded) method to take the four arguments:

.

public static void UpdateReseller(int resellerId, string resellerName, string resellerMobile, string resellerRefNum)
Comments