| 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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mamta MPosted Aug 4, 2011, 5:40 AM
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 LingePosted Aug 4, 2011, 8:17 AM
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.
neha dhimanPosted Aug 4, 2011, 7:59 AM
Dinesh BeniwalPosted Aug 4, 2011, 7:49 AM
If your query is Solved then Mark as accepted answer.
neha dhimanPosted Aug 4, 2011, 7:47 AM
Priya LingePosted Aug 4, 2011, 6:05 AM
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.