第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在C#程序中執(zhí)行存儲(chǔ)過(guò)程

如何在C#程序中執(zhí)行存儲(chǔ)過(guò)程

呼啦一陣風(fēng) 2019-06-14 10:29:04
如何在C#程序中執(zhí)行存儲(chǔ)過(guò)程我想從C#程序中執(zhí)行這個(gè)存儲(chǔ)過(guò)程。我在SQLSERVER查詢窗口中編寫了以下存儲(chǔ)過(guò)程,并將其保存為Store 1:use master  go create procedure dbo.test asDECLARE @command as varchar(1000), @i intSET @i = 0WHILE @i < 5BEGINPrint 'I VALUE ' +CONVERT(varchar(20),@i) EXEC(@command)SET @i = @i + 1END編輯:using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.SqlClient;namespace AutomationApp{     class Program     {         public void RunStoredProc()         {             SqlConnection conn = null;             SqlDataReader rdr  = null;             Console.WriteLine("\nTop 10 Most Expensive Products:\n");             try             {                 conn = new SqlConnection("Server=(local);DataBase=master;Integrated Security=SSPI");                 conn.Open();                 SqlCommand cmd = new SqlCommand("dbo.test", conn);                 cmd.CommandType = CommandType.StoredProcedure;                 rdr = cmd.ExecuteReader();                 /*while (rdr.Read())                 {                     Console.WriteLine(                         "Product: {0,-25} Price: ${1,6:####.00}",                         rdr["TenMostExpensiveProducts"],                         rdr["UnitPrice"]);                 }*/             }             finally             {                 if (conn != null)                 {                     conn.Close();                 }                 if (rdr != null)                 {                     rdr.Close();                 }             }         }         static void Main(string[] args)         {             Console.WriteLine("Hello World");             Program p= new Program();             p.RunStoredProc();                   Console.Read();         }     }}這將顯示異常。Cannot find the stored procedure dbo.test..我需要提供這條路嗎?如果是,應(yīng)將存儲(chǔ)過(guò)程存儲(chǔ)在哪個(gè)位置?
查看完整描述

3 回答

?
溫溫醬

TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊

using (var conn = new SqlConnection(connectionString))using (var command = new SqlCommand("ProcedureName", conn) { 
                           CommandType = CommandType.StoredProcedure }) {
   conn.Open();
   command.ExecuteNonQuery();}


查看完整回答
反對(duì) 回復(fù) 2019-06-14
?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

using (SqlConnection sqlConnection1 = new SqlConnection("Your Connection String")) {using (SqlCommand cmd = new SqlCommand()) {
  Int32 rowsAffected;

  cmd.CommandText = "StoredProcedureName";
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Connection = sqlConnection1;

  sqlConnection1.Open();

  rowsAffected = cmd.ExecuteNonQuery();}}


查看完整回答
反對(duì) 回復(fù) 2019-06-14
  • 3 回答
  • 0 關(guān)注
  • 1082 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)