Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
what is the wrong ??
try
 {
    SqlConnection con = new SqlConnection(@ "jjj");
    SqlCommand comm = new SqlCommand("select [??????_??????] from client where [???   _??????]= '" + comboBox1.SelectedValue + "' ", con);
   con.Open();
   prevtxt.Text =(string)comm.ExecuteScalar();
   con.Close();
 }
 catch (System.Exception ex)
 {
   MessageBox.Show(ex.Message);
  }
Posted 31-Jan-13 12:14pm
Edited 31-Jan-13 12:18pm
v3
Comments
DinoRondelly at 31-Jan-13 18:18pm
   
Is this a test? You tell me whats wrong ...
Winston Madiano at 1-Feb-13 0:49am
   
My idea, use sqlparameters for security against SQL injection. (Ex. command.parameters.addWithvalue("@","") )

If the datatype of your (Where [??? _??????]") is string then convert combobox Selected value to string.

Dispose your objects properly.. by using "using", or "dispose" keyword.
Sergey Alexandrovich Kryukov at 31-Jan-13 18:21pm
   
The questions like "what's wrong" cannot be valid if you don't tell us what do you try to achieve. What is wring for one purpose can be right for another...
Of course, if you stuff a query with ???????, you cannot expect anything good...
—SA
Member 9702410 at 31-Jan-13 18:33pm
   
NO , i already want to fill textbox using combobox value as where condition an i try this code but there is no text in textbox
DinoRondelly at 31-Jan-13 18:36pm
   
Does the query return anything?
Member 9702410 at 31-Jan-13 18:57pm
   
No.
DinoRondelly at 31-Jan-13 18:58pm
   
So the query doesnt return anything and you are wondering why the text box is empty?
Member 9702410 at 31-Jan-13 19:02pm
   
yes.
DinoRondelly at 31-Jan-13 19:03pm
   
If the query doesnt return a record then there is nothing to put in the text box and therefor the text box will not have a value, make sense?
Member 9702410 at 31-Jan-13 19:13pm
   
you can see the code again
 
try
{
SqlConnection con = new SqlConnection(@" mm");
SqlCommand comm = new SqlCommand("select name from client where id= '" + comboBox1.SelectedValue + "' ", con);
con.Open();
prevtxt.Text =(string)comm.ExecuteScalar();
con.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
Member 9702410 at 31-Jan-13 18:34pm
   
I'm sorry first ???????? represent column name and also second ???????? represent another column name
Member 9702410 at 31-Jan-13 18:59pm
   
the code again:
 
try
{
SqlConnection con = new SqlConnection(@" mm");
SqlCommand comm = new SqlCommand("select name from client where c_name= '" + comboBox1.SelectedValue + "' ", con);
con.Open();
prevtxt.Text =(string)comm.ExecuteScalar();
con.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
Sergey Alexandrovich Kryukov at 31-Jan-13 22:50pm
   
Please, stop writing this sample in comments. Can you see "Improve question" above?
Click it and put everything in one piece, the body of the question, taking account everything, and do it very clearly.
—SA
vinodkumarnie at 31-Jan-13 23:54pm
   
What is the data type of id(column) in your table....?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

your textbox need be active multiline and in the moment of asigment use the += and don't use only =
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100