1
you will need to write a SELECT query and retrieve information from the table into a datareader and then read records from the datareader
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];
Accepted 1
Hi Neha,
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.
0
hey priya thanx 4 replyin..but actually i am new at this so ..i dont know how to run the extracted file...if possible please reply back and explain the steps so that i can run the extracted files..i am having visual studio 2008 version and microsoft sql server management studio 2008....thanx..
0
Hi Neha,
If your query is Solved then Mark as accepted answer.
0
Thanku so much..it worked...
0
Hi Neha,
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.