1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| public void dataset()
{
try
{
int i = 2;
Boolean b = true;
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\abbeillle\\Documents\tablearbres.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlDataAdapter adap = new SqlDataAdapter();
adap.SelectCommand = new SqlCommand("select * from arbres ", Program.con);
adap.Fill(x,"arbres");
if (x.Tables["arbres"].Rows.Count == 0)
{
string req1 = "insert into arbres(idpos, position1) values ('" + textBox1.Text + "','" + textBox2.Text + "');";
con.Open();
comm = new SqlCommand(req1, con);
comm.ExecuteNonQuery();
MessageBox.Show("insertion bien faite ");
}
else
{
while ((i <= 7) && (b == true))
{
string req2 = "select position"+i +" from arbres where position='"+i+"' is null ";
if (x.Tables["arbres"].Rows.Count != 0)
{
int dernierLigne = x.Tables["arbres"].Rows.Count-1;
// string req1 = "update arbres set position"+i+" = " + textBox2.Text + " where position"+i+"=position"+i;
string req1 = "update arbres set position"+i+" = '" + textBox2.Text + "' where idpos like '" + x.Tables["arbres"].Rows[dernierLigne][0].ToString() + "'";
con.Open();
// comm = new SqlCommand(req2, con);
comm = new SqlCommand(req1, con);
comm.ExecuteNonQuery();
b = false;
MessageBox.Show(req1);
MessageBox.Show("Modification bien faite");
}
i++;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
} |
Partager