and table contains the statistics
how could I fill the statistics table by getting information from the result table
the statistics table columns are :
-club
-points
-sumgoals
and the results table columns are :
-club1
-goals1
-club2
-goals2
I attached the code that doesn't work
what is the completely code which include the dataReader and dataAdapter
and any thing else
please
I need your help ....... thanx
Expand|Select|Wrap|Line Numbers
- protected void Button2_Click(object sender, EventArgs e)
- {
- SqlConnection conn;
- conn = new SqlConnection();
- conn.ConnectionString = " Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\matches.mdf;Integrated Security=True;User Instance=True";
- conn.Open();
- sqlcommand selectingl;
- selecting = new sqlcommand();
- selecting.connection=conn;
- string select;
- select = "select * from result";
- selecting.commandtext=select;
- sqlcommand selectingl2;
- selecting = new sqlcommand();
- selecting.connection=conn;
- string select2;
- select = "select * from statistics";
- selecting.commandtext=select;
- dataset resultrecs;
- resultrecs = executedatareader();
- SqlCommand upcmd;
- upcmd = new SqlCommand();
- upcmd.Connection = conn;
- int i;
- i=0;
- string updating;
- while resultrecs.read()
- {
- updating= "Update statistics Set goals=goals+@goals,points=points+3,win=win+1,where club =@club)";
- upcmd.commandtext=updating;
- upcmd.parameters.add("goals",resultrecs.Tables["result"].Rows[i]["goals1"])
- upcmd.parameters.add("club",resultrecs.Tables["result"].Rows[i]["club1"])
- }
- SqlDataAdapter da;
- da = new SqlDataAdapter();
- da.UpdateCommand = upcmd;
- da.fill(resultrecs);
- da.update(resultrecs);
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- SqlConnection conn;
- conn = new SqlConnection();
- conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\matches.mdf;Integrated Security=True;User Instance=True";
- conn.Open();
- SqlCommand selectcmd;
- selectcmd = new SqlCommand();
- selectcmd.Connection = conn;
- string selecting;
- selecting = "select *from results ";
- selectcmd.CommandText = selecting;
- SqlDataReader dr;
- dr = selectcmd.ExecuteReader();
- int sumgoals;
- string tclub;
- string adding;
- SqlCommand insertcmd;
- insertcmd = new SqlCommand();
- insertcmd.Connection = conn;
- int i, j;
- while( dr.Read())
- {
- i = Convert.ToInt32( dr["goals1"]) ;
- j =Convert.ToInt32( dr["goals2"]);
- if (i>j)
- {
- adding = ("INSERT INTO statistics (goals,win,points) VALUES(@goals,@win,@points)where club=@club");
- insertcmd.CommandText = adding;
- insertcmd.Parameters.Add("club", dr["club1"]);
- insertcmd.Parameters.Add("goals", dr["goals1"]);
- insertcmd.Parameters.Add("win", 1);
- insertcmd.Parameters.Add("points", 3);
- // insertcmd.ExecuteNonQuery();
- }
- }
- //selectcmd.Parameters.Add("club", TextBox1.Text);
- //selectcmd.CommandText=selecting;
- //SqlCommand upcmd;
- //upcmd = new SqlCommand();
- //upcmd.Connection = conn;
- //string adcmd;
- //adcmd = "Update statistics Set goals=goals+2,points=points+3,win=win+1)";
- //upcmd.CommandText = adcmd;
- //SqlDataAdapter da;
- // da = new SqlDataAdapter();
- // da.SelectCommand = selectcmd;
- // da.UpdateCommand = upcmd;
- // DataSet newrecord;
- // newrecord = new DataSet();
- // da.Fill(newrecord);
- // da.UpdateCommand = upcmd;
- // da.Update(newrecord);
- // GridView1.DataSource = newrecord;
- // GridView1.DataBind();
- conn.Close();
- }
- }