Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am using comboboxes in my webform.i want to validate to my combobox.i am using parameterized query. if i do not select any item so a messagebox is working properly but after that error messages invokes. please check and guide me how to solve this problem.

What I have tried:

C#
if (string.IsNullOrEmpty(comboproductcategory.SelectedText))
                {
                    MessageBox.Show("please  select the item");
                }

                else if (comboproductcategory.SelectedText == " ")
                {
                  
                cmd.Parameters.AddWithValue("@ProductCategory",comboproductcategory.SelectedItem);
                }
                else
                {
                    MessageBox.Show("select again");
                } 
Posted
Updated 10-May-16 2:40am
v2
Comments
Karthik_Mahalingam 10-May-16 8:38am    
combobox in webform ??
what is the error message,
post full code related to your error
faizyab 2009 10-May-16 14:16pm    
this is a window form
faizyab 2009 10-May-16 14:20pm    
"The parameterized query '(@WarrantyOnSite nvarchar(3),@WarrantyOFFSite nvarchar(4000),@un' expects the parameter '@ProductCategory', which was not supplied."this is error
faizyab 2009 10-May-16 14:20pm    
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DCID;Integrated Security=True");
con.Open();
string query = "insert into DSIIDC_Component_List (FARNo,User1,User2,User3,Date,ProductCategory,Model,PurchaseOrderNo,Make,InvoiceNo,SerialNo,BriefDetails,SystemTransferDetails,ProductCost,VendorName,WarrantyUpTO,AMCFrom,AMCTO,AMCWith,IssuedOn,WarrantyOnSite,WarrantyOFFSite,underAMCYES) values(@FARNo,@User1,@User2,@User3,@Date,@ProductCategory,@Model,@PurchaseOrderNo,@Make,@InvoiceNo,@SerialNo,@BriefDetails,@SystemTransferDetails,@ProductCost,@VendorName,@WarrantyUpTO,@AMCFrom,@AMCTO,@AMCWith,@IssuedOn,@WarrantyOnSite,@WarrantyOFFSite,@underAMCYES)";
SqlCommand cmd = new SqlCommand(query, con);

bool flag = Isexsist(txtfrano.Text);
if (flag)
{
MessageBox.Show("ID is already");
}
else
{



string FAR = "";
if (string.IsNullOrEmpty(txtfrano.Text) || txtfrano.Text[0] == ' ')
{
MessageBox.Show("F.A R Number is empty");
return;
}
else
{
FAR = this.txtfrano.Text;
MessageBox.Show("FAR Number" + FAR);
}


string model = "";
if (string.IsNullOrEmpty(txtmodel.Text) || txtmodel.Text[0] == ' ')
{
MessageBox.Show("Model is empty");
return;
}
else
{
model = this.txtmodel.Text;
// MessageBox.Show("model is" + model);
}


string purchaseorderno = "";
if (string.IsNullOrEmpty(txtpurchaseorderno.Text) || txtpurchaseorderno.Text[0] == ' ')
{
MessageBox.Show("purchaseorderno is empty");
return;
}
else
{
purchaseorderno = this.txtpurchaseorderno.Text;
// MessageBox.Show("purchaseorderno is" + purchaseorderno);
}

string invoicno = "";
if (string.IsNullOrEmpty(txtinvoicno.Text) || txtinvoicno.Text[0] == ' ')
{
MessageBox.Show("invoicno is empty");
return;
}
else
{
invoicno = this.txtinvoicno.Text;
//MessageBox.Show("invoicno is" + invoicno);
}








string serialno = "";
if (string.IsNullOrEmpty(txtserialno.Text) || txtserialno.Text[0] == ' ')
{
MessageBox.Show("serialno is empty");
return;
}
else
{
serialno = this.txtserialno.Text;
// MessageBox.Show("serialno is" + serialno);
}


string briefConfiguration = "";

if (string.IsNullOrEmpty(txtbriefConfiguration.Text) || txtbriefConfiguration.Text[0] == ' ')
{
MessageBox.Show("serialno is empty");
return;
}
else
{
briefConfiguration = this.txtbriefConfiguration.Text;
//MessageBox.Show("briefConfiguration is" + briefConfiguration);
}

string systemtransfer = "";

if (string.IsNullOrEmpty(txtsystemtransfer.Text) || txtsystemtransfer.Text[0] == ' ')
{
MessageBox.Show("serialno is empty");
return;
}
else
{
syst

1 solution

you can use Jquery form validation IO with that you can achieve the validation. that plug in is superb
 
Share this answer
 
Comments
faizyab 2009 10-May-16 14:06pm    
Sir this is window form in C# . this is not a web page. how can we use jquery in this
Member 11127442 11-May-16 0:34am    
you mean to say you are trying to insert the value in db, if the combo box is empty then you are getting error, if so then, make a default value null to that colum or else
check or else use if statement, if its empty, don't add that query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900