Creating a checklist using checkbox tool in csharp smart device project
-
Hello, I am developing a GMAO csharp smart device application.I am in the step of creating a checklist using checkbox tool added dynamically:
I have two tables:Travaux (Works in English) and Actions related by the two fields Nature (table Travaux)and typeTravail(Table Actions).If the user enters the number of the work(NBT the pk_Travaux),the system adds a number of checkboxs equal to the steps that should the user follows to accomplish(field step in Actions table).After that,the user has the possibility to check or not the step if he did it.All the traitments will be done dynamically with the database
My select statement is:
select Etape from Action where ((Travaux.NBT=textbox1.text) and (Travaux.Nature=Action.TypeTravail))
Equal of what this select returns,it will add dynamically checkboxs I tried with this code but not working due to some errors :((
private void button1_Click(object sender, EventArgs e)
{
//Create the connection
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);//Create the command SqlCeCommand command = sqlceconn.CreateCommand(); command.CommandText = "Select NBT, Nature from Travaux where NBT=@NBT "; //Add the parameters string s1 = textBox1.Text; //store the login name here YOU MUST FILL THIS IN SqlCeParameter NBT = new SqlCeParameter("@NBT", SqlDbType.NVarChar); NBT.Value = s1; command.Parameters.Add(NBT); //Create the adapter SqlCeDataAdapter adapter = new SqlCeDataAdapter(command); //Create and fill the dataset DataSet ds = new DataSet(); try { adapter.Fill(ds, "SQL Temp Table"); } catch (Exception ex) { MessageBox.Show(ex.Message); } foreach (DataRow da in adapter) { string s = adapter\["Nature"\]; } if ((ds.Tables.Count > 0) && (ds.Tables\["SQL Temp Table"\] != null)) { MessageBox.Show("Number of row(s) - " + ds.Tables\["SQL Temp Table"\].Rows.Count); if (ds.Tables\["SQL Temp Table"\].Rows.Count > 0) { MessageBox.Show("Numéro de BT trouvé"); SqlCeCommand command1 = sqlceconn.CreateCommand();
-
Hello, I am developing a GMAO csharp smart device application.I am in the step of creating a checklist using checkbox tool added dynamically:
I have two tables:Travaux (Works in English) and Actions related by the two fields Nature (table Travaux)and typeTravail(Table Actions).If the user enters the number of the work(NBT the pk_Travaux),the system adds a number of checkboxs equal to the steps that should the user follows to accomplish(field step in Actions table).After that,the user has the possibility to check or not the step if he did it.All the traitments will be done dynamically with the database
My select statement is:
select Etape from Action where ((Travaux.NBT=textbox1.text) and (Travaux.Nature=Action.TypeTravail))
Equal of what this select returns,it will add dynamically checkboxs I tried with this code but not working due to some errors :((
private void button1_Click(object sender, EventArgs e)
{
//Create the connection
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);//Create the command SqlCeCommand command = sqlceconn.CreateCommand(); command.CommandText = "Select NBT, Nature from Travaux where NBT=@NBT "; //Add the parameters string s1 = textBox1.Text; //store the login name here YOU MUST FILL THIS IN SqlCeParameter NBT = new SqlCeParameter("@NBT", SqlDbType.NVarChar); NBT.Value = s1; command.Parameters.Add(NBT); //Create the adapter SqlCeDataAdapter adapter = new SqlCeDataAdapter(command); //Create and fill the dataset DataSet ds = new DataSet(); try { adapter.Fill(ds, "SQL Temp Table"); } catch (Exception ex) { MessageBox.Show(ex.Message); } foreach (DataRow da in adapter) { string s = adapter\["Nature"\]; } if ((ds.Tables.Count > 0) && (ds.Tables\["SQL Temp Table"\] != null)) { MessageBox.Show("Number of row(s) - " + ds.Tables\["SQL Temp Table"\].Rows.Count); if (ds.Tables\["SQL Temp Table"\].Rows.Count > 0) { MessageBox.Show("Numéro de BT trouvé"); SqlCeCommand command1 = sqlceconn.CreateCommand();
Tunisien86 wrote:
foreach (DataRow da in adapter) { string s = adapter["Nature"]; }
Should be
foreach (DataRow da in ds.Tables[0].Rows)
{
string s = da["Nature"];
}Tunisien86 wrote:
foreach (DataRow ligne in adapt.) { System.Console.WriteLine(adapt[0]); }
This should be
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
System.Console.WriteLine(dataRow[0]);
} -
Tunisien86 wrote:
foreach (DataRow da in adapter) { string s = adapter["Nature"]; }
Should be
foreach (DataRow da in ds.Tables[0].Rows)
{
string s = da["Nature"];
}Tunisien86 wrote:
foreach (DataRow ligne in adapt.) { System.Console.WriteLine(adapt[0]); }
This should be
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
System.Console.WriteLine(dataRow[0]);
}Hi, Thanks Reddy,the errors disappears all with some corrections:
foreach (DataRow da in ds.Tables[0].Rows)
{
string s = da[0].ToString();}.I want now to add every row it found after executing the select request:
command1.CommandText = "Select NoEtape, Etape from Action where TypeTravail=@typ ";
I create a listview and I wanna add like items every result of the select.I modify my code in his end like this:
............
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
ListViewItem item = new ListViewItem();
item.Text = dataRow[0].ToString();
listView1.Items.Add(item);
System.Console.WriteLine(dataRow[0]);
}} else MessageBox.Show("Veuillez saisir un autre NBT"); } adapter.Dispose(); sqlceconn.Dispose(); command.Dispose(); } }
But this modification doesn't show any thing in the listviewitem. Thanks a lot for u suggestions :((
-
Hi, Thanks Reddy,the errors disappears all with some corrections:
foreach (DataRow da in ds.Tables[0].Rows)
{
string s = da[0].ToString();}.I want now to add every row it found after executing the select request:
command1.CommandText = "Select NoEtape, Etape from Action where TypeTravail=@typ ";
I create a listview and I wanna add like items every result of the select.I modify my code in his end like this:
............
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
ListViewItem item = new ListViewItem();
item.Text = dataRow[0].ToString();
listView1.Items.Add(item);
System.Console.WriteLine(dataRow[0]);
}} else MessageBox.Show("Veuillez saisir un autre NBT"); } adapter.Dispose(); sqlceconn.Dispose(); command.Dispose(); } }
But this modification doesn't show any thing in the listviewitem. Thanks a lot for u suggestions :((
Tunisien86 wrote:
dat.Tables[0].Rows
Did you check if the DataTable has any rows after executing the select statement? Does it even get into the foreach loop?
-
Tunisien86 wrote:
dat.Tables[0].Rows
Did you check if the DataTable has any rows after executing the select statement? Does it even get into the foreach loop?
Hi, Thank u for u help.I found the solution using the listview tool(with its option checked) and all gets well.This is the link after that solved my issue: http://msdn.microsoft.com/en-us/library/ms229643.aspx[^] Thanks a lot and can u have a look to my new thread:DataGridView-DataBase in csharp smart device posted a few minutes ago Thanks :)