0

I have implemented standalone Email notify service using c#. I have two DB, "KIBS_UMS" which I retrieve data of user's Email and required to append to DB "FBS". I need a solution to how to pass "userEmail" in "KIBS_UMS" to "to_list" in "FBS". I already retrieved user details from "KIBS_UMS". I need to know insert into "FBS". Here's the code I done

get user details from SQL table

try
{
    const string ConnectionString = "Data Source=DESKTOP-C5RCC1K\\SQL2016EXPRESS;Initial Catalog=KIBS_UMS;Integrated Security=True";
    SqlConnection con = new SqlConnection(ConnectionString);
    con.Open();

    SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[User] where userStatus = 'Active'");
    cmd.Connection = con;

    SqlDataReader reader = cmd.ExecuteReader();

    if (reader.Read())
    {
        Console.WriteLine(reader["UserName"].ToString());

        Console.WriteLine(reader["UserEmail"].ToString());

        Console.ReadLine();

    }
    else
    {
        Console.WriteLine("Error reading user in Database");
        return;
    }

    con.Close();
}
catch (Exception e)
{
    Console.WriteLine("Error in reading user details..." + e.Message);
}

append result to the Email table

try
{
    SqlConnection conn = new SqlConnection("Data Source=DESKTOP-C5RCC1K\\SQL2016EXPRESS;Initial Catalog=FBS;Integrated Security=True");
    conn.Open();

    string query = "INSERT INTO [FBS].[dbo].[tbl_email_list] (to_list, cc_list, subject, body, status, generated_time, booking_code";

    query += "VALUES (@to_list, @cc_list, @subject, @body, @status, @generated_time, @booking_code)";

    SqlCommand myCommand = new SqlCommand(query, conn);

    // need a solution how to append

}
catch (Exception e)
{
    Console.WriteLine("Error in reading user details..." + e.Message);
}
3
  • 2
    Does this answer your question? Batch Update/insert in using SQLCommand in C# Commented Apr 7, 2022 at 6:17
  • You need to provide some values for those parameters in your INSERT command and then execute the command Commented Apr 7, 2022 at 6:42
  • Could able to show me how to doing it? I had that idea but don't know how to do. Commented Apr 7, 2022 at 8:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.