i want to update the details in a form it shows the errors(windows applications)?

Posted by Sudheep.grandhe under C# on 11/19/2011 | Points: 10 | Views : 1712 | Status : [Member] | Replies : 2
Hi,

i want to update the details in a form it shows the errors(windows applications)?.please do the needful/
Errors:
Error:-Operator '==' cannot be applied to operands of type 'System.Windows.Forms.TextBox' and 'string'
Error:-Operator '||' cannot be applied to operands of type 'bool' and 'string'
Error:-The best overloaded method match for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments
Error:-Argument '2': cannot convert from 'System.Data.SqlClient.SqlCommand' to 'System.Data.SqlClient.SqlConnection'

private void btn_update_Click(object sender, EventArgs e)
{
try
{
if ((txt_customeraddress.Text == "" || txt_invoiceno.Text == "" || txt_orderno.Text = ""))
{
MessageBox.Show("Fill All Entries:");
}
else if (txt_customeraddress == txt_customeraddress.Text && txt_invoiceno.Text == txt_invoiceno.Text && txt_orderno.Text == txt_orderno.Text)
{
}
else
{
SqlCommand cmd = new SqlCommand("update tbl_report2 set compname=@compname,compaddress=@compaddress,orderno=@orderno,ondate=@ondate,invoicedate=@invoicedate,amountstatus=@amountstatus,netamount=@netamount,tamount=@tamount where invoiceno=@id", cmd);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@compname", cmb_companyname.Text);
cmd.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd.Parameters.AddWithValue("@id", txt_invoiceno.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Data Successfully Updated");

}
}
catch (Exception ae) { MessageBox.Show(ae.ToString()); }


}

}

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/21/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

How did you write this code

else if (txt_customeraddress == txt_customeraddress.Text && txt_invoiceno.Text == txt_invoiceno.Text && txt_orderno.Text == txt_orderno.Text)
{
}

i didn't understand the purpose this statement. In this statement you didn't use .Text(see underline content). This is the reason for the error.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

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

Posted by: Vanajasethu on: 11/24/2011 [Member] Starter | Points: 25

Up
0
Down
Error 1:: use if (txt_customeraddress.ToString() == txt_customeraddress.Text.ToString() && txt_invoiceno.Text.ToString() == txt_invoiceno.Text.ToString() && txt_orderno.Text.ToString() == txt_orderno.Text.ToString() )

Error 2:: use
if ((txt_customeraddress.Text == "") ||( txt_invoiceno.Text == "" )||( txt_orderno.Text = ""))

Error 3 and Error 4 :: you are using cmd instead of sqlconnection in the below code

SqlCommand cmd = new SqlCommand("update tbl_report2 set compname=@compname,compaddress=@compaddress,orderno=@orderno,ondate=@ondate,invoicedate=@invoicedate,amountstatus=@amountstatus,netamount=@netamount,tamount=@tamount where invoiceno=@id", cmd );



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

Login to post response