C # calls itself to define table type parameters

Source: Internet
Author: User

-sql server generates a test environment:

--Create Test dbcreate database sales;gouse salesgo--CREATE TABLE type if type_id (' Localdt ') is not nulldrop type Localdtgo create type Localdt As TABLE (ID INT not null,name NVARCHAR ()) go--Create stored procedure if object_id (' p_datatable ', ' P ') is not nulldrop PROC p_datatable; Gocreate PROCEDURE p_datatable (@LocalDT Localdt READONLY) asselect * from @LocalDTGO

--Open visual studio-Create Project-Select "Console Application"

Using system;using system.collections.generic;using system.linq;using system.text;using System.Data;using            System.data.sqlclient;namespace procdatatable{class Program {static void Main (string[] args) {            DataTable dt = new DataTable ("Localdt"); Dt.            Columns.Add ("ID", typeof (int)); Dt.            Columns.Add ("Name", typeof (String)); DataRow dr = dt.            NewRow ();            Dr[0] = 1;            DR[1] = "Roy"; Dt.            Rows.Add (DR); SqlConnection thisconnection = new SqlConnection (@ "server= instance name; database=sales; User Id=sa;            Password=1 ");            Thisconnection.open ();            SqlCommand sqlcmd = Thisconnection.createcommand ();            Sqlcmd.commandtype = CommandType.StoredProcedure;            Sqlcmd.commandtext = "P_datatable"; SqlParameter param = sqlcmd.            Parameters.addwithvalue ("@LocalDT", DT); SqlDataReader SDR = sqlcmd.            ExecuteReader (); while (SDR. Read ()) {ConsoLe.            WriteLine ("Id:{0}\tname:{1}", sdr[0],sdr[1]);              } thisconnection.close ();          Console.readkey (); }    }}

-Test results:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "/>



C # calls itself to define table type parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.