It shows the error in the following code [Resolved]

Posted by Sudheep.grandhe under C# on 10/18/2011 | Points: 10 | Views : 2349 | Status : [Member] | Replies : 6
Hi,

It shows the error in the following code.can you please help me to resolve this error.please do the needful

Error 1:-The best overloaded method match for 'System.Data.SqlClient.SqlParameterCollection.AddWithValue(string, object)' has some invalid arguments
Error 2:-Argument '2': cannot convert from 'method group' to 'object'

Best,
Sudheep.



Responses

Posted by: Ndebata on: 10/18/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Every where ToString() is a method or function but you have omitted the parenthesis
write
cmb_companyname.SelectedItem.ToString()


Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 10/18/2011 [Member] Bronze | Points: 25

Up
0
Down
hi sudeep, will plz show your code from where this error comes.

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 10/18/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Error 1:-The best overloaded method match for 'System.Data.SqlClient.SqlParameterCollection.AddWithValue(string, object)' has some invalid arguments.I am underliying the error part.please find.
private void btn_add_Click(object sender, EventArgs e)
{
string strondate, strondate1, ondate;
string strinvoicedate, strinvoicedate1, invoicedate2;
SqlConnection con = new SqlConnection("data source=mars-104;intial catalog=marsweb.imageimpacts;integrated security=true");
SqlCommand cmd = new SqlCommand("insert into tbl_temp (invoiceno,particulars,quantiy,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid)values(@invoiceno,@particulars,@quantity,@perprice,@amount,@orderno,@compname,@invoicedate,@ondate,@invoiceid)", con);
cmd.Parameters.AddWithValue("@invoiceno", txt_invoiceno.Text);
cmd.Parameters.AddWithValue("@particulars", cmb_particulars.SelectedItem.ToString);
cmd.Parameters.AddWithValue("@quantity", txt_quantity.Text);
cmd.Parameters.AddWithValue("@perprice", txt_perprice.Text);
cmd.Parameters.AddWithValue("@amount", txt_amount.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.SelectedItem.ToString);

Error 2:-Argument '2': cannot convert from 'method group' to 'object' .I am underliying the error part.please find.

private void cmb_companyname_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=mars-104;intial catalog=marsweb.imageimpacts;integrated security=true");
SqlCommand cmd = new SqlCommand("select custaddress from tbl_customer where custname=@custname", con);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.SelectedItem.ToString) ;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
txt_customeraddress.Text = dt.Rows[0][0].ToString();
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 10/18/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

It shows the error in the following code.can you please help me to resolve this error.please do the needful
Error 1:-Argument '2': cannot convert from 'void' to 'object'
Error 2:-The best overloaded method match for 'System.Data.SqlClient.SqlParameterCollection.AddWithValue(string, object)' has some invalid arguments


cmd.Parameters.AddWithValue("@amount", rb_paid.Select);
cmd.Parameters.AddWithValue("@amount", rb_unpaid.Select);

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/18/2011 [Member] Starter | Points: 25

Up
0
Down
If rb_paid or rb_unpaid you are using are radio buttons and you are trying to save they are checked or not
cmd.Parameters.AddWithValue("@amount", rb_paid.Checked); 


Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mittaikariss on: 10/18/2011 [Member] Bronze | Points: 25

Up
0
Down
combo cox using this code

cmd.Parameters.AddWithValue("@particulars", cmb_particulars.SelectedItem.ToString() ); 


check box using this code...

cmd.Parameters.AddWithValue("@amount", rb_paid.Checked ); 

cmd.Parameters.AddWithValue("@amount", rb_unpaid.Checked );


http://www.invomtech.com/

....sundarsowmia....

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response