C++: read SQL server data using System::Data::SqlClient;

2023-11-09

stdafx.h:

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
#pragma once
#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
#using <System.Xml.dll>
// TODO: reference additional headers your program requires here

Form1.h

#pragma once
 
 
namespace SQLServer2008R2inCCLI {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::Configuration;
    using namespace ADODB;//c:\Program Files\Common Files\System\ADO\msado15.dll
 
    using namespace System::Data::SqlClient;
 
    /// <summary>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    ///          'Resource File Name' property for the managed resource compiler tool
    ///          associated with all .resx files this class depends on.  Otherwise,
    ///          the designers will not be able to interact properly with localized
    ///          resources associated with this form.
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }
 
    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
            private: System::Windows::Forms::DataGridView^ dataGridView1;
        private: System::Windows::Forms::Label^ label1;
        private: System::Windows::Forms::ComboBox^ comboBoxTables;
        private: System::Windows::Forms::Button^ buttonOK;
        private: System::Windows::Forms::ToolTip^ toolTip1;
    private: System::ComponentModel::IContainer^  components;
    protected:
 
    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
 
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->components = (gcnew System::ComponentModel::Container());
            this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->comboBoxTables = (gcnew System::Windows::Forms::ComboBox());
            this->buttonOK = (gcnew System::Windows::Forms::Button());
            this->toolTip1 = (gcnew System::Windows::Forms::ToolTip(this->components));
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->BeginInit();
            this->SuspendLayout();
            //
            // dataGridView1
            //
            this->dataGridView1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
                | System::Windows::Forms::AnchorStyles::Left)
                | System::Windows::Forms::AnchorStyles::Right));
            this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
            this->dataGridView1->Location = System::Drawing::Point(12, 44);
            this->dataGridView1->Name = L"dataGridView1";
            this->dataGridView1->ShowCellToolTips = false;
            this->dataGridView1->Size = System::Drawing::Size(493, 266);
            this->dataGridView1->TabIndex = 0;
            this->dataGridView1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::dataGridView1_MouseDown);
            this->dataGridView1->DataError += gcnew System::Windows::Forms::DataGridViewDataErrorEventHandler(this, &Form1::dataGridView1_DataError);
            //
            // label1
            //
            this->label1->Location = System::Drawing::Point(12, 9);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(65, 32);
            this->label1->TabIndex = 1;
            this->label1->Text = L"Select table to show:";
            //
            // comboBoxTables
            //
            this->comboBoxTables->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
            this->comboBoxTables->FormattingEnabled = true;
            this->comboBoxTables->Location = System::Drawing::Point(83, 12);
            this->comboBoxTables->Name = L"comboBoxTables";
            this->comboBoxTables->Size = System::Drawing::Size(165, 21);
            this->comboBoxTables->TabIndex = 2;
            //
            // buttonOK
            //
            this->buttonOK->Location = System::Drawing::Point(254, 12);
            this->buttonOK->Name = L"buttonOK";
            this->buttonOK->Size = System::Drawing::Size(56, 21);
            this->buttonOK->TabIndex = 3;
            this->buttonOK->Text = L"OK";
            this->buttonOK->UseVisualStyleBackColor = true;
            this->buttonOK->Click += gcnew System::EventHandler(this, &Form1::buttonOK_Click);
            //
            // toolTip1
            //
            this->toolTip1->AutoPopDelay = 5000;
            this->toolTip1->InitialDelay = 0;
            this->toolTip1->IsBalloon = true;
            this->toolTip1->ReshowDelay = 0;
            this->toolTip1->ToolTipIcon = System::Windows::Forms::ToolTipIcon::Warning;
            this->toolTip1->UseAnimation = false;
            this->toolTip1->UseFading = false;
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(517, 322);
            this->Controls->Add(this->buttonOK);
            this->Controls->Add(this->comboBoxTables);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->dataGridView1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &Form1::Form1_FormClosed);
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->EndInit();
            this->ResumeLayout(false);
 
        }
#pragma endregion
        String ^ServerName, ^DBName;
 
        SqlConnection ^conn;
        SqlDataAdapter ^adapter;
        DataTable ^dtMain;
 
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                 ServerName = "GEOVINDU-PC\\GEOVIN";
                 DBName = "DuVehicle";
 
 
 
                 // create database if not exists
                 //try {
                    // ADODB::Connection="";//c:\Program Files\Common Files\System\ADO\msado15.dll
 
                                     // connect to server
                 // to database "master" to check if our database exists
                 // to create it if it isn't exists
                 //conn = gcnew SqlConnection("Server=" + ServerName + ";Database=DuVehicle;UID=sa;PWD=geovindu;");
                 //conn->Open();
                     //SqlCommand ^cmd = gcnew SqlCommand(String::Format("CREATE DATABASE [{0}] ON (" +
      //                                              "    NAME = {0}, " +
                        //                          "    FILENAME = '" + Application::StartupPath + "\\{0}.mdf'" +
      //                                              ");",
      //                                              DBName), conn);
      //               cmd->ExecuteNonQuery();
                     //delete cmd;
                /* }
                 catch (Exception ^ex) { }*/
 
 
                 // create table "Table 1" if not exists
                 //SqlCommand ^cmd = gcnew SqlCommand(String::Format(
     //                                 "IF NOT EXISTS (" +
     //                                 "    SELECT [name] " +
     //                                 "    FROM sys.tables " +
     //                                 "    WHERE [name] = '{0}'" +
     //                                 ") " +
     //                                 "CREATE TABLE [{0}] (" +
     //                                 "    id [INT] IDENTITY(1,1) PRIMARY KEY CLUSTERED, " +
     //                                 "    [text column] [TEXT] NULL, " +
     //                                 "    [int column] [INT] NULL " +
     //                                 ")",
     //                                 "Table 1"), conn);
     //          cmd->ExecuteNonQuery();
                 //delete cmd;
                 conn = gcnew SqlConnection("Server=" + ServerName + ";Database=DuVehicle;UID=sa;PWD=geovindu;");
                 conn->Open();
                 // get all tables from DB
                 DataTable ^dt = conn->GetSchema("Tables");
                 for (int i = 0; i < dt->Rows->Count; i++) {
                    if (dt->Rows[i]->ItemArray[dt->Columns->IndexOf("TABLE_TYPE")]->ToString() == "BASE TABLE") {
                        comboBoxTables->Items->Add(dt->Rows[i]->ItemArray[dt->Columns->IndexOf("TABLE_NAME")]->ToString());
                    }
                 }
                 delete dt;
             }
private: System::Void buttonOK_Click(System::Object^  sender, System::EventArgs^  e) {
             if (comboBoxTables->SelectedItem == nullptr) return;
 
             adapter = gcnew SqlDataAdapter("SELECT * FROM [" + comboBoxTables->SelectedItem->ToString() + "]", conn);
 
             gcnew SqlCommandBuilder(adapter);
 
             dtMain = gcnew DataTable();
             adapter->Fill(dtMain);
             dtMain->Columns["id"]->ReadOnly = true; // deprecate id field edit to prevent exceptions
             dataGridView1->DataSource = dtMain;
         }
private: System::Void Form1_FormClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e) {
             if (adapter == nullptr) return;
 
             adapter->Update(dtMain);
         }
         // show tooltip (not intrusive MessageBox) when user trying to input letters into INT column cell
private: System::Void dataGridView1_DataError(System::Object^  sender, System::Windows::Forms::DataGridViewDataErrorEventArgs^  e) {
             if (dtMain->Columns[e->ColumnIndex]->DataType == Int64::typeid ||
                 dtMain->Columns[e->ColumnIndex]->DataType == Int32::typeid ||
                dtMain->Columns[e->ColumnIndex]->DataType == Int16::typeid)
            {
                Rectangle ^rectColumn;
                rectColumn = dataGridView1->GetColumnDisplayRectangle(e->ColumnIndex, false);
 
                Rectangle ^rectRow;
                rectRow = dataGridView1->GetRowDisplayRectangle(e->RowIndex, false);
 
                toolTip1->ToolTipTitle = "This field is for numbers only.";
                toolTip1->Show(" ",
                          dataGridView1,
                          rectColumn->Left, rectRow->Top + rectRow->Height);
 
                delete rectColumn;
                delete rectRow;
            }
         }
private: System::Void dataGridView1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
             toolTip1->Hide(dataGridView1);
         }
};
}


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++: read SQL server data using System::Data::SqlClient; 的相关文章

  • EF Core Group By 翻译支持条件总和

    听说 EF Core 2 1 将支持翻译小组 我感到非常兴奋 我下载了预览版并开始测试它 但发现我在很多地方仍然没有得到翻译分组 在下面的代码片段中 对 TotalFlagCases 的查询将阻止翻译分组工作 无论如何 我可以重写这个以便我
  • 没有强命名的代码签名是否会让您的应用程序容易被滥用?

    尝试了解authenticode代码签名和强命名 我是否正确地认为 如果我对引用一些 dll 非强命名 的 exe 进行代码签名 恶意用户就可以替换我的 DLL 并以看似由我签名但正在运行的方式分发应用程序他们的代码 假设这是真的 那么您似
  • 我如何才能等待多个事情

    我正在使用 C 11 和 stl 线程编写一个线程安全队列 WaitAndPop 方法当前如下所示 我希望能够将一些内容传递给 WaitAndPop 来指示调用线程是否已被要求停止 如果 WaitAndPop 等待并返回队列的元素 则应返回
  • 以文化中立的方式将字符串拆分为单词

    我提出了下面的方法 旨在将可变长度的文本拆分为单词数组 以进行进一步的全文索引处理 删除停止词 然后进行词干分析 结果似乎不错 但我想听听关于这种实现对于不同语言的文本的可靠性的意见 您会建议使用正则表达式来代替吗 请注意 我选择不使用 S
  • GLKit的GLKMatrix“列专业”如何?

    前提A 当谈论线性存储器中的 列主 矩阵时 列被一个接一个地指定 使得存储器中的前 4 个条目对应于矩阵中的第一列 另一方面 行主 矩阵被理解为依次指定行 以便内存中的前 4 个条目指定矩阵的第一行 A GLKMatrix4看起来像这样 u
  • 在结构中使用 typedef 枚举并避免类型混合警告

    我正在使用 C99 我的编译器是 IAR Embedded workbench 但我认为这个问题对于其他一些编译器也有效 我有一个 typedef 枚举 其中包含一些项目 并且我向该新类型的结构添加了一个元素 typedef enum fo
  • 为什么当实例化新的游戏对象时,它没有向它们添加标签? [复制]

    这个问题在这里已经有答案了 using System Collections using System Collections Generic using UnityEngine public class Test MonoBehaviou
  • OleDbDataAdapter 未填充所有行

    嘿 我正在使用 DataAdapter 读取 Excel 文件并用该数据填充数据表 这是我的查询和连接字符串 private string Query SELECT FROM Sheet1 private string ConnectStr
  • Clang 3.1 + libc++ 编译错误

    我已经构建并安装了 在前缀下 alt LLVM Clang trunk 2012 年 4 月 23 日 在 Ubuntu 12 04 上成功使用 GCC 4 6 然后使用此 Clang 构建的 libc 当我想使用它时我必须同时提供 lc
  • 不同枚举类型的范围和可转换性

    在什么条件下可以从一种枚举类型转换为另一种枚举类型 让我们考虑以下代码 include
  • C#中如何移动PictureBox?

    我已经使用此代码来移动图片框pictureBox MouseMove event pictureBox Location new System Drawing Point e Location 但是当我尝试执行时 图片框闪烁并且无法识别确切
  • 将多个表映射到实体框架中的单个实体类

    我正在开发一个旧数据库 该数据库有 2 个具有 1 1 关系的表 目前 我为每个定义的表定义了一种类型 1Test 1Result 我想将这些特定的表合并到一个类中 当前的类型如下所示 public class Result public
  • 显示UnityWebRequest的进度

    我正在尝试使用下载 assetbundle统一网络请求 https docs unity3d com ScriptReference Networking UnityWebRequest GetAssetBundle html并显示进度 根
  • SolrNet连接说明

    为什么 SolrNet 连接的容器保持静态 这是一个非常大的错误 因为当我们在应用程序中向应用程序发送异步请求时 SolrNet 会表现异常 在 SolrNet 中如何避免这个问题 class P static void M string
  • 转发声明和包含

    在使用库时 无论是我自己的还是外部的 都有很多带有前向声明的类 根据情况 相同的类也包含在内 当我使用某个类时 我需要知道该类使用的某些对象是前向声明的还是 include d 原因是我想知道是否应该包含两个标题还是只包含一个标题 现在我知
  • WPF/C# 将自定义对象列表数据绑定到列表框?

    我在将自定义对象列表的数据绑定到ListBox in WPF 这是自定义对象 public class FileItem public string Name get set public string Path get set 这是列表
  • 通过指向其基址的指针删除 POD 对象是否安全?

    事实上 我正在考虑那些微不足道的可破坏物体 而不仅仅是POD http en wikipedia org wiki Plain old data structure 我不确定 POD 是否可以有基类 当我读到这个解释时is triviall
  • C# 模拟VolumeMute按下

    我得到以下代码来模拟音量静音按键 DllImport coredll dll SetLastError true static extern void keybd event byte bVk byte bScan int dwFlags
  • C# - OutOfMemoryException 在 JSON 文件上保存列表

    我正在尝试保存压力图的流数据 基本上我有一个压力矩阵定义为 double pressureMatrix new double e Data GetLength 0 e Data GetLength 1 基本上 我得到了其中之一pressur
  • Windows 和 Linux 上的线程

    我在互联网上看到过在 Windows 上使用 C 制作多线程应用程序的教程 以及在 Linux 上执行相同操作的其他教程 但不能同时用于两者 是否存在即使在 Linux 或 Windows 上编译也能工作的函数 您需要使用一个包含两者的实现

随机推荐

  • linux内核分析:进程通讯方式

    信号 一旦有信号产生 我们就有下面这几种 用户进程对信号的处理方式 1 执行默认操作 Linux 对每种信号都规定了默认操作 例如 上面列表中的 Term 就是终止进程的意思 Core 的意思是 Core Dump 也即终止进程后 通过 C
  • 解决M1处理器安装PS闪退问题Photoshop 2021 fo mac(支持最新M1芯片处理器款mac)

    去年苹果在2020年11月11日突然发布了搭载自研M1芯片处理器的最新款Mac 由于这次新版mac系列史无前例的采用arm架构的芯片 导致很多之前为旧版mac开发的软件安装后不兼容无法使用 这其中就包括著名的Adobe系列软件 之前很多刚买
  • ppocrlabel简单教学

    前言 给我们小白成员的快速上手ppocrlabel的指南 1 ppocr环境配置 建议是先创建一个虚拟环境 直接参考 https blog csdn net weixin 42708301 article details 119864744
  • HDMI的DDC是什么

    DDC 是什么 DDC Display Data Channel 显示数据通道 在 HDMI 协议中用于 Source 和 Sink 两端进行数据交换 通常是基于 I2C 标准的一套通讯机制 在实际使用过程中 Source 端的 HDMI
  • 前端自动化测试之葵花宝典

    作者 京东零售 杜兴文 首先聊一下概念 Web 前端自动化测试是一种通过编写代码来自动化执行 Web 应用程序的测试任务的方法 它通常使用 JavaScript 和测试框架 如 Selenium Appium 等 来实现 Web 前端自动化
  • IRQL 和 分页内存

    IRQL是Interrupt ReQuest Level 中断请求级别 一个由windows虚拟出来的概念 划分在windows下中断的优先级 这里中断包括了硬中断和软中断 硬中断是由硬件产生 而软中断则是完全虚拟出来的 处理器在一个IRQ
  • python中把list列表所有或者部分的数变成整数,或者浮点数,字符串等等

    第一种 简单形式列表中是数字型 list x 1624865249825 0 316 0 351 0 32 0 107 0 4 0 1 7187 2970 0 1 0 list y 5249825 4 0 925 0 3903 1 7187
  • STM32HAL库 (cubemx) 两个HC05蓝牙模块相互通信相关问题的解决 数组串口发送与接受的方法

    主要问题 1 蓝牙模块的连接问题 2 蓝牙模块的工作模式 3 CUBEMX 配置串口注意事项 4 两个模块数据传输异常 前言 因为最近都在做基于STM32 MPU6050的手势控制机器人 遇到了无线数据传输的问题 正好手上有几个蓝牙模块 就
  • Latex系列2---段落编写+标题编写+目录生成

    接着上一节的简单中文文本 这节阐述的是一篇小规模文章的编写 段落编写 分段 写文章少不了分段的情况 latex中如何分段 先看一段代码和效果图 在这里我们看到代码中对于文章的分段有两种方式 1 空行 2 使用 par 空格 的形式 对于空行
  • blender基础笔记

    1 下载与安装 官网下载 官网下载 setam下载 steam下载 个人推荐这个 方便 修改语言 左上角 edit preferences Interface Transtation Langlish 疲了 看图吧 懒得写了 2 基础操作
  • 源码看CoordinatorLayout.Behavior原理

    http blog csdn net qibin0506 article details 50377592 在上一篇博客CoordinatorLayout高级用法 自定义Behavior中 我们介绍了如何去自定义一个CoordinatorL
  • Java中变量的作用域详解

    作用域定义 字面解释 scope 域即一定范围内的较大的地方 顾名思义就是在一定的范围内起作用 大白话解释 父母在家的时候能控制你的玩与学习 出了家门说了也白说 老师在校的时候能够管理你的行为 出了学校你都想管管他 这就是说 不管什么样的指
  • 单表数据量达多少时才建议分库分表

    1 阿里巴巴开发手册建议是 推荐 单表行数超过500万行或者单表容量超过2GB 才推荐进行分库分表 说明 如果预计三年后的数据量根本达不到这个级别 请不要在创建表时就分库分表 2 实际情况还要根据机器的配置视情况而定 3 阿里巴巴开发手册下
  • oracle生成UUID

    oracle生成UUID uuid Universally Unique Identifier 全局唯一标识符 是指在一台机器上生成的数字 它保证对在同一时空中的所有机器都是唯一的 按照开放软件基金会 OSF 制定的标准计算 用到了以太网卡
  • leetcode题解:最长公共前缀

    leetcode题解 最长公共前缀 题目描述 编写一个函数来查找字符串数组中的最长公共前缀 如果不存在公共前缀 返回空字符串 示例 1 输入 flower flow flight 输出 fl 示例 2 输入 dog racecar car
  • [Docker]Elasticsearch启动报错:Format version is not supported

    如果之前安装过Elasticsearch 安装新的Elasticsearch之前需要清空宿主机器对应的挂载目录下的文件数据
  • 打百万拳,走万里路。

    自我介绍 CSDN的大家你们好啊 我是一名大一的学生 与CSDN的相识还要从大一一次次查找知识点开始 当时由于刚接触编程 做什么都一头雾水而又不想去问老师那些简单的知识 于是自己在网上查找 就发现了CSDN这个大学生聚集地 由于很多都是和我
  • Python单重循环练习题

    第一次学python 求大佬指正 1 有1020个西瓜 第一天卖掉总数的一半后又多卖出两个 以后每天卖剩下的一半多两个 问几天以后能卖完 8天后能卖完 sum 1020 day 0 while sum gt 0 day 1 sum sum
  • 解决tomcat 启动超过45秒时间限制

    当在eclipse运行一个javaweb项目时 出现了如下图片中的问题 解决方法 1在如下页面中找到Servers 找不到的话可以通过Window gt gt Show View放到下方 2 双击Servers进到如下页面 3 打开箭头所指
  • C++: read SQL server data using System::Data::SqlClient;

    stdafx h stdafx h include file for standard system include files or project specific include files that are used frequen