如何将sql查询放在表格中的一列中? [英] how can put a sql query in the one of my column in a table?

查看:210
本文介绍了如何将sql查询放在表格中的一列中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTime thisday = DateTime.Now;
    MySqlConnection con = new MySqlConnection("Server=localhost;UID=root;Database=db_cignal");
    con.Open();
    MySqlCommand cmd = con.CreateCommand();
    cmd.CommandText = "insert into revenue(Year,Newsales,Beginninginventory,Purchases,Goodforsales,Endinventory,Costofsales,Salesandwages,sss,Rental,Postage,Lightandwater,Freight,Fuel,Officesupplies,Taxesandlicenses,Representation,Depreciation,Transportation,Repairs,Miscellaneous,Totaloperatingexpense,Provisions,Netincomefinal)values(@one,@two,@three,@four,@five,@six,@seven,@eight,@nine,@ten,@eleven,@twelve,@thirteen,@fourteen,@fifteen,@sixteen,@seventeen,@eighteen,@nineteen,@twenty,@twentyone,@twentytwo,@twentythree,@twenthfour,@twentyfive)";
    cmd.Parameters.AddWithValue("@one", thisday.ToString("d"));
    cmd.Parameters.AddWithValue("@two", TotalPriceQuery());

private void TotalPriceQuery()
{
    MySqlConnection con = new MySqlConnection("Server=localhost;UID=root;Database=db_cignal");
    con.Open();
    MySqlCommand cmd = con.CreateCommand();
    cmd.CommandText = "SELECT SUM(TotalPrice) FROM inventoryout";
    cmd.Prepare();
    cmd.ExecuteNonQuery();
    con.Close();

}



i知道错了,但我希望你明白我的观点:)


i know its wrong but i hope you get my point :)

推荐答案

这里有很多问题。



1.问题不明确。

2.你定义了很多参数,但是通过只有两个。不确定是否要传递其他人。

2.对于参数 @two ,您要分配一个方法,其返回类型为 void
You have many issues here.

1. Question is not clear.
2. You have many parameters defined, but passing only two. Not sure if you are passing others.
2. For the parameter @two, you are assigning a method, whose return type is void.


所以我想在这里做的是在sales列中,要存储在sales表中的数据库中的值是库存表中所有总价格的总和
So what i wanted to do here is in the sales column, the value to be stored in the database in the sales table is the sum of all total price in inventoryout table


这篇关于如何将sql查询放在表格中的一列中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆