Getting data from another table

Posted by Jammyhunt under ASP.NET on 3/15/2013 | Points: 10 | Views : 731 | Status : [Member] | Replies : 2
Greets Everyone..

i have grid view like this
picture below..

http://i48.tinypic.com/vdd1qa.png

now i want a new page naming result... which will have only total of table1(pic provided above)..
and i want it to result like this.

RESULTS
ID school_name maths_total science_total computer_total
1. karen's 700 1000 1050

i have a table naming result for this

source code in my result page's load event

string connstr = "provider=microsoft.ace.oledb.12.0;data source=c:\\users\\jammy\\documents\\visual studio 2010\\websites\\testing\\app_data\\test.accdb;persist security info=true";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = connstr;

OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.InsertCommand = new OleDbCommand();
adapter.InsertCommand.CommandText = "INSERT INTO result('name',mat_total','sci_total,'com_total') SELECT SUM(math),SUM(science),SUM(computer) FROM table1";
conn.Open();
adapter.InsertCommand.Connection = conn;
adapter.InsertCommand.ExecuteNonQuery();


whenever i am debbuging, i got this error

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

kindly help me with this source




Responses

Posted by: Raj.Trivedi on: 3/17/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Jammy,

You are not specifying the values names while inserting in values section

adapter.InsertCommand.CommandText = "INSERT INTO result('name',mat_total','sci_total,'com_total') values('val1','val2,'val3','val4')

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Brahmam on: 3/18/2013 [Member] Starter | Points: 25

Up
0
Down
adapter.InsertCommand.CommandText = "INSERT INTO result('name',mat_total','sci_total,'com_total') SELECT SUM(math),SUM(science),SUM(computer) FROM table1";

this not correct formated sql query
select*from table1 here * means your Selected the values

brahmam

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response