Friday, December 30, 2016

Connecting SQL Store procedure from VS with parameter Ax 2012

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SangeetDemo
{
    public partial class Form1 : Form
    {
        SqlConnection con;
        SqlCommand command;
        string sqlcon = @"Server=Sangeeth-PC\DEV01;Database=AdventureWorks2012;User ID=sa; Password=1234";
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection();
            con.ConnectionString = sqlcon;
            try
            {
                con.Open();
                command = new SqlCommand();
                command.Connection = con;
                command.CommandText = "Proc_Test";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@name", "abc");
                command.Parameters.AddWithValue("@trns_dt", DateTime.UtcNow);
                SqlDataReader reader = command.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        MessageBox.Show(reader["SalesOrderID"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...