TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
roohollah azari
NA
38
1.6k
transfer datatable data to labels with for while
Jun 26 2015 7:19 PM
hello! how are you?
i have a problem in developing my project.
i want that in my project create label dynamically to (number of database(datatable)rows count * columns count) and fill that labels with datatable Informations but we have a many errors:The following sourcecode:
private void TxtSearch_TextChanged(object sender, EventArgs e)
{
string selectstr = "";
SqlConnection conn = new SqlConnection(adresedatabase);
switch (comboBox1.SelectedIndex)
{
case 0:
{
selectstr = "select * from TblKala where Barcode =@barcode";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conn;
da.SelectCommand.CommandText = selectstr;
da.SelectCommand.Connection = conn;
da.SelectCommand.Parameters.AddWithValue("@barcode", Convert.ToInt32(TxtSearch.Text));
conn.Open();
DataTable dt = new DataTable();
da.Fill(dt);
object result = da.SelectCommand.ExecuteScalar();
rs = Convert.ToInt32 (result);
conn.Close();
System.Windows.Forms.Label[] lb = new System.Windows.Forms.Label[Convert.ToInt32(result) * 7];
for (int i = 0; i < Convert.ToInt32(result); i++)
for (int j = 0, px = 30, py = 30; j <= 6; i++)
{
lb[Convert.ToInt32(i.ToString() + j.ToString())].Text = dt.Rows[i].ItemArray[j].ToString(); //error line//
lb[Convert.ToInt32(i.ToString() + j.ToString())].Name = "lb" + i.ToString() + j.ToString(); //error line//
this.Controls.Add(lb[Convert.ToInt32(i.ToString() + j.ToString())]); //error line//
lb[Convert.ToInt32(i.ToString() + j.ToString())].Location = new System.Drawing.Point(px, py); //error line//
px += 30;
}
break;
}
}
}
database design:
database data:
please help me. resolve that.
Reply
Answers (
2
)
Modify an existing word table using c#
How to post json data to http request?