简体   繁体   English

如何获取 sum(Net_weight) 以从 MySQL 查询结果并使用 ID 保存到 MSSQL

[英]How to get sum(Net_weight) in to query result from MySQL and save in to MSSQL with ID

I have Query Like SELECT SUM(Length) FROM tbl_test WHERE ID = @ID and date= @date I am assigning Date into the string我有像SELECT SUM(Length) FROM tbl_test WHERE ID = @ID and date= @date这样的查询我将日期分配到字符串中

MysqlConnection con = new mysqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString());
mySqlCommand read_command = new mySqlCommand("SELECT SUM(Length) FROM tbl_test ID =@ID and date=@date", con);
        read_command.Parameters.Add("@Date", SqlDbType.Date).Value = yesterday ;
        mySqlDataReader read_rd;
        string SUM ;
        try
        {
            con.Open();
            read_rd = read_command.ExecuteReader();
            if (read_pass_rd.HasRows)
            {
                while (read_rd.Read())
                {
                    SUM = read_rd.GetString(0);
                }
            }
            read_rd.Close();
            con.Close();
        }
        catch (Exception)
        {
            if (con.State == ConnectionState.Open)

When running this query I am getting query result using My SQL.运行此查询时,我使用 My SQL 获取查询结果。 Now the problem is I need to save query result Sum(length) to save MSSQL table with id and Yesterday date.现在的问题是我需要保存查询结果 Sum(length) 以保存带有 id 和昨天日期的 MSSQL 表。 How to save into MS SQL Table because this windows service application how to save ID and Yesterday Date.如何保存到 MS SQL 表中,因为此 Windows 服务应用程序如何保存 ID 和昨天的日期。

You can create a connection of MSSql similar to MySQL.您可以创建一个类似于 MySQL 的 MSSql 连接。 And pass Id , Sum , and DateTime.Now.AddDays(-1) to insert query of MS SQL.并通过IdSumDateTime.Now.AddDays(-1)插入 MS SQL 的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM