从 C# 执行 SQL Server 存储过程

我在 C# 控制台应用程序中执行我的存储过程时遇到问题,我不知道问题是什么。你能看一下吗?


string path="";


StringBuilder sb = new StringBuilder();

StringBuilder sqlErrorMessages = new StringBuilder("Sql Exception:\n");


try

    SqlConnection conn = new SqlConnection("Data Source=DESKTOP-M3IMRLE\\SQLEXPRESS; Initial Catalog = db2; Integrated security=true");


    Console.WriteLine("Enter path : ");

    path = Console.ReadLine();

    conn.Open();


    SqlCommand cmd = new SqlCommand();


    SqlCommand command = new SqlCommand("EXECUTE main.mainproc @path='" + path + "'", conn);


    if(command!=null)

    { 

        Console.WriteLine("JSON loaded");

    }  


    conn.Close();

}

catch(SqlException ex)

{

    sqlErrorMessages.AppendFormat("Message: {0}\n", ex.Message);

}


慕娘9325324
浏览 170回答 2
2回答

慕码人8056858

你还没有调用ExecuteNonQuery你的 SqlCommandcommand.ExecuteNonQuery()
打开App,查看更多内容
随时随地看视频慕课网APP