473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

updating database by another

I have a table contains the results of matches
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
  1. protected void Button2_Click(object sender, EventArgs e)
  2.     {
  3.         SqlConnection conn;
  4.         conn = new SqlConnection();
  5.         conn.ConnectionString = " Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\matches.mdf;Integrated Security=True;User Instance=True";
  6.  
  7.         conn.Open();
  8.     sqlcommand selectingl;
  9.     selecting = new sqlcommand();
  10.     selecting.connection=conn;
  11.     string select;
  12.     select = "select * from result";
  13.     selecting.commandtext=select;
  14.  
  15.         sqlcommand selectingl2;
  16.     selecting = new sqlcommand();
  17.     selecting.connection=conn;
  18.     string select2;
  19.     select = "select * from statistics";
  20.     selecting.commandtext=select;
  21.  
  22.     dataset resultrecs;
  23.     resultrecs = executedatareader();
  24.  
  25.         SqlCommand upcmd;
  26.         upcmd = new SqlCommand();
  27.         upcmd.Connection = conn;
  28.  
  29.     int i;
  30.     i=0;
  31.         string updating;
  32.     while resultrecs.read()
  33.     {
  34.                 updating= "Update statistics Set goals=goals+@goals,points=points+3,win=win+1,where club =@club)";
  35.         upcmd.commandtext=updating;
  36.         upcmd.parameters.add("goals",resultrecs.Tables["result"].Rows[i]["goals1"])        
  37.         upcmd.parameters.add("club",resultrecs.Tables["result"].Rows[i]["club1"])                
  38.  
  39.     }
  40.              SqlDataAdapter da;
  41.              da = new SqlDataAdapter();
  42.              da.UpdateCommand = upcmd;
  43.          da.fill(resultrecs);
  44.         da.update(resultrecs);
  45.     }
  46. }
  47.  
  48. protected void Button1_Click(object sender, EventArgs e)
  49.     {
  50.         SqlConnection conn;
  51.         conn = new SqlConnection();
  52.         conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\matches.mdf;Integrated Security=True;User Instance=True";
  53.  
  54.         conn.Open();
  55.  
  56.         SqlCommand selectcmd;
  57.         selectcmd = new SqlCommand();
  58.         selectcmd.Connection = conn;
  59.         string selecting;
  60.         selecting = "select *from results ";
  61.         selectcmd.CommandText = selecting;
  62.         SqlDataReader dr;
  63.         dr = selectcmd.ExecuteReader();
  64.         int sumgoals;
  65.         string tclub;
  66.         string adding;
  67.         SqlCommand insertcmd;
  68.         insertcmd = new SqlCommand();
  69.         insertcmd.Connection = conn;
  70.         int i, j;
  71.         while( dr.Read())
  72.         {
  73.             i =  Convert.ToInt32( dr["goals1"]) ;
  74.             j =Convert.ToInt32( dr["goals2"]);
  75.             if (i>j)
  76.             {
  77.                 adding = ("INSERT INTO statistics (goals,win,points) VALUES(@goals,@win,@points)where club=@club");
  78.                 insertcmd.CommandText = adding;
  79.                 insertcmd.Parameters.Add("club", dr["club1"]);
  80.                 insertcmd.Parameters.Add("goals", dr["goals1"]);
  81.                 insertcmd.Parameters.Add("win", 1);
  82.                 insertcmd.Parameters.Add("points", 3);
  83.                // insertcmd.ExecuteNonQuery();
  84.             }           
  85.         }
  86.         //selectcmd.Parameters.Add("club", TextBox1.Text);
  87.         //selectcmd.CommandText=selecting;
  88.         //SqlCommand upcmd;
  89.         //upcmd = new SqlCommand();
  90.         //upcmd.Connection = conn;
  91.         //string adcmd;
  92.         //adcmd = "Update statistics Set goals=goals+2,points=points+3,win=win+1)";
  93.          //upcmd.CommandText = adcmd;
  94.  
  95.     //SqlDataAdapter da;
  96.     //   da = new SqlDataAdapter();
  97.     //   da.SelectCommand = selectcmd;
  98.     //   da.UpdateCommand = upcmd;
  99.  
  100.     //  DataSet newrecord;
  101.     //   newrecord = new DataSet();
  102.     //   da.Fill(newrecord);
  103.     //   da.UpdateCommand = upcmd;
  104.  
  105.     //   da.Update(newrecord);
  106.     //   GridView1.DataSource = newrecord;
  107.     //   GridView1.DataBind();
  108.        conn.Close();
  109.     }
  110. }
  111.  
Attached Files
File Type: txt New Text Document.txt (3.8 KB, 369 views)
Apr 7 '10 #1
2 1449
tlhintoq
3,525 Expert 2GB
In the future just copy/paste your code between [code] tags rather than the attachment. Most people will react faster if they can just look at the code rather than have to download it.
Apr 7 '10 #2
Frinavale
9,735 Expert Mod 8TB
That's quite a bit of code to look through to try and guess what isn't working.
Could you please post why it isn't working?
Include details like any error message you're getting....what line you think is causing problems...what exactly the program is or isn't doing correctly.

-Frinny
Apr 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
0
by: Bob Kaku | last post by:
I'm trying to create a text editing and updating capability to help someone who wants to maintain content on a web page without having to know any HTML or use a web authoring tool and FTP'ng the...
0
by: cwbp17 | last post by:
Have two tables that have a FK relationship on ID column. Have one datagrid that displays all of the columns of both tables. What's the best approach on updating a row from the datagrid back to...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
6
by: Derek Hart | last post by:
I am using a status bar to show progress for a long database update. With the single threading, the GUI often gets stuck and does not show updating, especially when the user clicks to another...
5
by: aaron.m.johnson | last post by:
I have an application which contains an Access database with linked tables that point to another database within the application. The problem I have is that when the user installs the application,...
0
by: OldStd | last post by:
Updating data using 2 data sets I am having some problems in updating the database using two datasets as suggested by someone. 1. Data is displayed in a data grid from a dataset generated using...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.