Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Wednesday, March 28, 2012

How to show data in a Label item?

SqlCeConnection cn = new SqlCeConnection("Data Source=\\Program Files\\test\\tel.sdf");
try
{
SqlCeCommand cmd = cn.CreateCommand();

cmd.CommandText = "SELECT * from phone where PhoneNo = '0912312345'";

SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);

DataSet ds = new DataSet();

adp.Fill(ds);
this.dataGrid1.DataSource = ds.Tables[0];

label1.Text =Convert.ToString(?);

label2.Text =Convert.ToString(?);

}

finally
{
if (cn.State != ConnectionState.Closed)
{
cn.Close();
}
}

I can show the result in the DataGrid1

however, I want the label1 to show the Name,

and label2 to show the phoneNo.

how to do in here,

label1.Text =Convert.ToString(?);

label2.Text =Convert.ToString(?);

thanks

DataSet is a collection of DataTables and DataTable is a collection of rows and columns. You can access data in the table directly as you would do it with array:

label1.Text = ds.Tables[0].Rows[row_index_here][colum_index_or_name_here].ToString();

Alternatively you can bind your label so it would be updated automatically as you change current row in the grid:

label1.DataBindings.Add("Text", ds.Tables[0], "ColumnNameHere");

sql

Monday, March 12, 2012

How to set the current connectionString user as a defualt value?

Hi,

I'm using username & password in my connectionString to connect my program (C#.net) with Sql Server 2005..

I put in defualt value in one feild: user_name()

it replace the user: dbo, not the user which I used in my connectionString.

so.. how to get this user?

I tried to put: currnet_user

but I get the same result, "dbo" not the user in my connectionString..

I tried SESSION_USER, it gave the same result :(|||

This is my connectionString:

connectionString="Provider=SQLOLEDB;Data Source=LEWEHSBF\LEWEENG;Persist Security Info=True;Password=HsBfL4w4;User ID=Lewe;Initial Catalog=MyDatabase"

|||

I think the resone is the user I which I used in myConnectionString, is Admin user, I tried with "dataread, datawrite" user and its worked..

Thank you myself