| mov | time | day |
| lion | 9:00 | sunday |
| cat | 9:00 | sunday |
| lion | 12:00 | sunday |
| cat | 12:00 | sunday |
I want to retrieve and display different time of mov=lion for day=sunday in two textbox in visual studio 2008 using c sharp
| mov | time | day |
| lion | 9:00 | sunday |
| cat | 9:00 | sunday |
| lion | 12:00 | sunday |
| cat | 12:00 | sunday |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mamta MRank #268 · 9.4K reputationPosted Aug 4, 2011, 1:40 AM EDT
the SELECT statement can be similar to below:
SELECT time from movies where mov="lion" and day="sunday"
then in the while loop where you are interating through the datareader,
assign the datareader's first value into the first element of an array and next value to the next element
int i=0;
while(reader.Read())
{
strTime[i] = reader.GetString(0).ToString();
...
}
txtTime1.Text = strTime[0];
txtTime2.Text = strTime[1];
Priya LingeRank #785 · 2.9K reputationPosted Aug 4, 2011, 2:05 AM EDT
You want to display two diff values form same coloumn in textbox, you can do it by following way.
public partial class Form1 : Form
{
SqlConnection sqlConnection = new SqlConnection("Data Source=TFSERVER;Initial Catalog=pub4;Persist Security Info=True;User ID=trustfort;Password=Admin@123");
SqlCommand sqlCommand;
SqlDataReader sqlReader;
SqlDataAdapter da;
DataSet ds;
public Form1()
{
InitializeComponent();
getdata();
}
public void getdata()
{
string query = "select Name from Customer";
sqlConnection.Open();
sqlCommand = new SqlCommand(query, sqlConnection);
da = new SqlDataAdapter(sqlCommand);
ds = new DataSet();
da.Fill(ds);
//DataTable tb = ds.Tables[0];
txtfirst.Text = ds.Tables[0].Rows[0][0].ToString();
txtsecond.Text=ds.Tables[0].Rows[1][0].ToString();
}
Please check attached file.}
Hope this will help you.
Thanks.
neha dhiman14 reputationPosted Aug 4, 2011, 3:47 AM EDT
Dinesh BeniwalRank #9 · 64K reputationPosted Aug 4, 2011, 3:49 AM EDT
If your query is Solved then Mark as accepted answer.
neha dhiman14 reputationPosted Aug 4, 2011, 3:59 AM EDT
Priya LingeRank #785 · 2.9K reputationPosted Aug 4, 2011, 4:17 AM EDT
I have one table name Customer ,it has two columns name ID and Name.
Just add connection to this table from sqlserver,Select 1 column name 'Name' from that table.
string query = "select Name from Customer";
fill this data in dataset as below.
here we got the column and rows of table.
ds.Tables[0] means in ds we have Customer table data.
Customer Table
Id Name
1 Vinay
2 Prakash
3 samir
As per you requirement we want diff vaules from same column ,let's say Name column.
I took ds.Tables[0].Row[0][0].
here Tables[0] ---------Customer Table which is in sql.
Row[0]--------------From Customer first name here we get 'Vinay'
[0]------------------Indiactes First column(Name) as i took in my query. Select Name from Customer.
ds.Tables[0].Row[1][0].
Row[1]--------------From Customer first name here we get Prakash
[0]------------------From same column means Name column.
I hope you get the idea about mentioned code.
Thanks.