SORU
11 AĞUSTOS 2009, Salı


C içinde saklı bir yordamı çalıştırmak için nasıl# program

C bu saklı yordamı çalıştırmak istiyorum# programı.

SQL sorgu penceresinde aşağıdaki saklı yordam yazdım ve kaydedilen stored1:

use master 
go
create procedure dbo.test as

DECLARE @command as varchar(1000), @i int
SET @i = 0
WHILE @i < 5
BEGIN
Print 'I VALUE '  CONVERT(varchar(20),@i)
EXEC(@command)
SET @i = @i   1
END

DÜZENLENMİŞTİR:

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();
        }
    }
}

Bu durum Cannot find the stored procedure dbo.test görüntüler. Yol sağlamak gerekiyor mu? Evet, hangi konumda saklanan prosedürleri saklanmalıdır?

CEVAP
11 AĞUSTOS 2009, Salı


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

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • captainpuppys2000

    captainpuppy

    20 HAZİRAN 2013
  • Emotional Trancer

    Emotional Tr

    4 Mart 2010
  • xXGAMERrs_Xx

    xXGAMERrs_Xx

    31 Temmuz 2014