last day (15 days later) » 

6:36 PM
1
A: Search for text value in sql table and display it in listbox on textbox.textChanged event

HoraciuxHere's the general idea... ListBox lb = new ListBox(); string connectionString = "your connection string here"; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); string query = "SELECT Name + ' ' + cast(Date as varchar(20))+' '+ cast(Value as varchar(20)) as '...

 
ok so this gives me all rows from "column" what if i want to give me all rows from all columns
 
It gives you only column for all rows from myitemstable. If you need more columns you have 2 choices. Concatenate all columns in SQL "Select column1+' ' +Column2 from..." and no changes in C#. Or "SELECT column1, column2 from.." and add a reader for each column in c# (string)reader["column1"]; (string)reader["column2"];
@Arch_interpreter What do you want to display in listbox?
 
ok so i do "SELECT column1, column2 from.." and then ` ListBox2.Items.Add( new ListItem((string)reader["Name"]) + ""+new ListItem((string)reader["Value"]) + ""+new ListItem((string)reader["Date"]) );` But "Value" column is float how to convert it to string
i want to display all the table content in the listbox ,so each row is in new line
 
@Arch_interpreter Do this: "SELECT Name + ' ' + cast(Date as varchar(20)+' '+ cast(Value as varchar(20) from.." now, from the point of view of c# all strings in only one column.
@Arch_interpreter see my edition to answer. This would work for you
 
hi
can i ask you here
 
6:37 PM
tell me
 
so

string query = "SELECT Name + ' ' + cast(Date as varchar(20)+' '+ cast(Value as varchar(20) FROM Table1";
using (SqlCommand cmd = new SqlCommand(queryy, con))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ListBox2.Items.Add(
new ListItem((string)reader["Name"])
+ ""+new ListItem((string)reader["Value"])
+ ""+new ListItem((string)reader["Date"])
);



}
}
}
what to write inside ListBox2.Items.Add();
 
string query = "SELECT Name + ' ' + cast(Date as varchar(20))+' '+ cast(Value as varchar(20)) FROM Table1";
using (SqlCommand cmd = new SqlCommand(queryy, con))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ListBox2.Items.Add(
new ListItem((string)reader["Text"])

);
wait
string query = "SELECT Name + ' ' + cast(Date as varchar(20))+' '+ cast(Value as varchar(20)) as 'Text' FROM Table1";
using (SqlCommand cmd = new SqlCommand(queryy, con))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ListBox2.Items.Add(
new ListItem((string)reader["Text"])

);
 
what is "Text" in this situation btw
 
is an alias I just added. when 3 columns get concatenated this columns has no name, I call it 'Text'
Select ..... AS 'Text' from...
it could be named as you like, remember to use same name in c#
 
y sec
im getting incorect syntax in cmd command
 
6:42 PM
queryy
replace queryy with query
 
did it
Incorrect syntax near '+'.
 
what is the name of the table?
 
string query = "SELECT Name + ' ' + cast(Date as varchar(20)+' '+ cast(Value as varchar(20) as 'Text' FROM Table1";

using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ListBox2.Items.Add(
new ListItem((string)reader["Text"])

);


}
}
}
 
string query = "SELECT Name + ' ' + cast(Date as varchar(20))+' '+ cast(Value as varchar(20)) as 'Text' FROM Table1";
I forgot )
Do you remover blank space on propose?
 
works now
:)
nice
 
6:45 PM
+ ' ' + is used for separation + '-' +
glad it work
pleas accept the answer
 
y
what about
+ 'insert tab '+
 
in c# is '\t' I think
google it
 
so + '/t' + ?
 
ok
 
oh my falut
i place it in SQL command :D
so where should i add the tab when i have
ListBox2.Items.Add(new ListItem((string)reader["Text"]) );
 
6:48 PM
check it, I don't remember '/t' ot '\t'
 
it is \t
 
yes, you shoud insert it in SQL
 
checked it but
inset in in SQL ?
aha
 
string query = "SELECT Name + '/t' + cast(Date as varchar(20))+'/t '+ cast(Value as varchar(20)) as 'Text' FROM Table1";
 
mhm this just adds /t to the text
hmm
 
6:50 PM
//t maybe?
I don't remember
112
Q: Inserting a tab character into text using C#

LaylaI'm building an application where I should capture several data and buil a text with them: Name, Age, etc... The output will be a plain text into a TextBox. I am trying to make those information appear in kind of "columns", therefore I am trying to separate them with "tabs" to make it clearer. ...

 
yea im watching this link
 
string query = "SELECT Name + '\t' + cast(Date as varchar(20))+'\t '+ cast(Value as varchar(20)) as 'Text' FROM Table1";
good bye
 

last day (15 days later) »