Click here to Skip to main content
Sign Up to vote bad
good
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:14
Edited 31 Jan '13 - 12:18

Comments
DinoRondelly - 31 Jan '13 - 18:18
Is this a test? You tell me whats wrong ...
Winston Madiano - 1 Feb '13 - 0:49
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 - 31 Jan '13 - 18:21
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 - 31 Jan '13 - 18:33
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 - 31 Jan '13 - 18:36
Does the query return anything?
Member 9702410 - 31 Jan '13 - 18:57
No.
DinoRondelly - 31 Jan '13 - 18:58
So the query doesnt return anything and you are wondering why the text box is empty?
Member 9702410 - 31 Jan '13 - 19:02
yes.
DinoRondelly - 31 Jan '13 - 19:03
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 - 31 Jan '13 - 19:13
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 - 31 Jan '13 - 18:34
I'm sorry first ???????? represent column name and also second ???????? represent another column name
Member 9702410 - 31 Jan '13 - 18:59
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 - 31 Jan '13 - 22:50
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 - 31 Jan '13 - 23:54
What is the data type of id(column) in your table....?

1 solution

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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 173
2 Abhinav S 168
3 Guirec Le Bars 120
4 Ron Beyer 100
0 Sergey Alexandrovich Kryukov 8,439
1 OriginalGriff 6,681
2 CPallini 3,553
3 Rohan Leuva 2,793
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid