C#winform连接MYSQL数据库斑马打印机打印标签

这篇具有很好参考价值的文章主要介绍了C#winform连接MYSQL数据库斑马打印机打印标签。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

C#winform连接MYSQL数据库斑马打印机打印标签 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using WindowsFormsMySql;
using BarTender;
using Microsoft.Build.BuildEngine;
using System.Data.SqlClient;


namespace printf
{
    public partial class commonprintf : Form
    {


        private static BarTender.Application btApp = new BarTender.Application();
        private static BarTender.Format btFormat = new BarTender.Format();

        //----------------------------------------------------------数据库连接-----------------------------------------------------------------
        MySqlConnection connection;
        public commonprintf()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {


            


            
        }
        //---------------------------------------------连接---------------------------------------------------
        private void button2_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;port=3306;user=root;password=20010612Syf@;database=mytest;";
            connection = new MySqlConnection(connStr);
            try
            {
                connection.Open();
                MessageBox.Show("连接成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;

            }
        }
        //----------------------------------------断开-----------------------------------------------------------------
        private void button3_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;port=3306;user=root;password=20010612Syf@;database=mytest;";
            connection = new MySqlConnection(connStr);
            try
            {
                connection.Close();
                MessageBox.Show("断开");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;

            }
        }
      

     

        private void button2_Click_1(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog();
            if (f2.DialogResult == DialogResult.OK)
            {
                //this.textBox1.Text = f2.str;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.ShowDialog();
            if (f3.DialogResult == DialogResult.OK)
            {
                
            }
        }
    }    
    
}

 C#winform连接MYSQL数据库斑马打印机打印标签

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using WindowsFormsMySql;
using BarTender;
using Microsoft.Build.BuildEngine;
using System.Data.SqlClient;

namespace printf
{
    public partial class Form2 : Form
    {
        private static BarTender.Application btApp = new BarTender.Application();
        private static BarTender.Format btFormat = new BarTender.Format();

        //----------------------------------------------------------数据库连接-----------------------------------------------------------------
        MySqlConnection connection;
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            dataShow();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;port=3306;user=root;password=20010612Syf@;database=mytest;";
            connection = new MySqlConnection(connStr);
            try
            {
                connection.Open();
                MessageBox.Show("连接成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;port=3306;user=root;password=20010612Syf@;database=mytest;";
            connection = new MySqlConnection(connStr);
            try
            {
                connection.Close();
                MessageBox.Show("断开");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;

            }
        }
        private void dataShow()
        {



            // 数据库连接
            DBhelper sqlhelper = new DBhelper();
            //创建DataSet对象
            // DataSet reader = sqlhelper.GetDataSet("select b.Productcode as 'Productcode' , b.Part as 'Part' ,b.Pm as 'Pm',b.Vollage as 'Vollage',b.Colour as 'Colour',b.SAP as  'SAP',b.Type as 'Type',b.Date as  'Date',b.Line as  'Line' from label b", "label");
            DataSet reader = sqlhelper.GetDataSet("select b.Class as 'Class' , b.Color as 'Color' ,b.Date as 'Date',b.Fab as 'Fab',b.Line as 'Line',b.Part as  'Part',b.Pm as 'Pm',b.Type as  'Type' from chejian b", "chejian");
            // 给显示控件赋值
            this.dataGridView1.DataSource = reader.Tables[0];
            // 外观自适应宽度
            for (int i = 0; i < dataGridView1.ColumnCount; i++)
            {
                dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;//自适应列宽
            }
            //-------------------------------------------------连接-------------------------------------------------------------------------

        }

        private void button4_Click(object sender, EventArgs e)
        {
            // 数据库连接
            DBhelper sqlhelper = new DBhelper();

            // sql语句
            //string sql = " update label set  Productcode  ='" + textBox1.Text + "',Part='" + textBox2.Text + "',Pm='" + textBox3.Text + "',Vollage='" + textBox4.Text + "',Colour='" + textBox5.Text + "',SAP='" + textBox6.Text + "',Type='" + textBox7.Text + "',Date='" + textBox8.Text + "',Line='" + textBox9.Text + "'where Productcode  ='" + textBox1.Text + "'";
            string sql = " update chejian set  Part  ='" + textBox1.Text + "',Class='" + textBox2.Text + "',Color='" + textBox3.Text + "',Date='" + textBox4.Text + "',Fab='" + textBox5.Text + "',Line='" + textBox6.Text + "',Pm='" + textBox7.Text + "',Type='" + textBox8.Text + "'where Part  ='" + textBox1.Text + "'";

            try
            {
                //创建DataSet对象
                sqlhelper.GetSqlCom(sql);
                dataShow();
            }
            catch
            {
                MessageBox.Show("修改失败");
            }

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // 获取选中行的某个数据
            int rowindex = e.RowIndex;
            try
            {
                textBox1.Text = dataGridView1.Rows[rowindex].Cells[0].Value.ToString();
                textBox2.Text = dataGridView1.Rows[rowindex].Cells[1].Value.ToString();
                textBox3.Text = dataGridView1.Rows[rowindex].Cells[2].Value.ToString();
                textBox4.Text = dataGridView1.Rows[rowindex].Cells[3].Value.ToString();
                textBox5.Text = dataGridView1.Rows[rowindex].Cells[4].Value.ToString();

                textBox6.Text = dataGridView1.Rows[rowindex].Cells[5].Value.ToString();
                textBox7.Text = dataGridView1.Rows[rowindex].Cells[6].Value.ToString();
                textBox8.Text = dataGridView1.Rows[rowindex].Cells[7].Value.ToString();
               // textBox9.Text = dataGridView1.Rows[rowindex].Cells[8].Value.ToString();
            }
            catch
            {
                MessageBox.Show("赋值异常");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 数据库连接
            DBhelper sqlhelper = new DBhelper();

            // sql语句
            // string sql = "INSERT INTO `label` VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "')";
            string sql = "INSERT INTO `chejian` VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')";

            try
            {
                //创建DataSet对象
                sqlhelper.GetSqlCom(sql);
                dataShow();
            }
            catch
            {
                MessageBox.Show("插入数据异常");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            // 数据库连接
            DBhelper sqlhelper = new DBhelper();

            // sql语句
            //string sql = " delete from label where Productcode='" + textBox1.Text + "'";
            string sql = " delete from chejian where Part='" + textBox1.Text + "'";
            try
            {
                //创建DataSet对象
                sqlhelper.GetSqlCom(sql);
                dataShow();
            }
            catch
            {
                MessageBox.Show("删除失败");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            {
                try
                {


                    btFormat = btApp.Formats.Open(AppDomain.CurrentDomain.BaseDirectory + "车间.btw", false, "");
                    btFormat.SetNamedSubStringValue("Class", textBox1.Text);
                    btFormat.SetNamedSubStringValue("Color", textBox2.Text);
                    btFormat.SetNamedSubStringValue("Date", textBox3.Text);
                    btFormat.SetNamedSubStringValue("Fab", textBox4.Text);
                    btFormat.SetNamedSubStringValue("Line", textBox5.Text);

                    btFormat.SetNamedSubStringValue("Part", textBox6.Text);
                    btFormat.SetNamedSubStringValue("Pm", textBox7.Text);
                    btFormat.SetNamedSubStringValue("Type", textBox8.Text);
                    //btFormat.SetNamedSubStringValue("Line", textBox9.Text);


                    btFormat.PrintOut(true, false); //第二个false设置打印时是否跳出打印属性
                    btFormat.Close(BarTender.BtSaveOptions.btSaveChanges);//退出是是否保存标签
                }
                catch
                {
                    MessageBox.Show("打印失败");
                }

            }
        }
        
        private void button7_Click(object sender, EventArgs e)
        {
          
        
            

            this.DialogResult = DialogResult.OK;
        
        }
    }
}

C#winform连接MYSQL数据库斑马打印机打印标签  文章来源地址https://www.toymoban.com/news/detail-512543.html

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using WindowsFormsMySql;
using BarTender;
using Microsoft.Build.BuildEngine;
using System.Data.SqlClient;


namespace printf
{
    public partial class Form3 : Form
    {
        private static BarTender.Application btApp = new BarTender.Application();
        private static BarTender.Format btFormat = new BarTender.Format();

        //----------------------------------------------------------数据库连接-----------------------------------------------------------------
        MySqlConnection connection;
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dataShow();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;port=3306;user=root;password=20010612Syf@;database=mytest;";
            connection = new MySqlConnection(connStr);
            try
            {
                connection.Open();
                MessageBox.Show("连接成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;port=3306;user=root;password=20010612Syf@;database=mytest;";
            connection = new MySqlConnection(connStr);
            try
            {
                connection.Close();
                MessageBox.Show("断开");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;

            }
        }
        private void dataShow()
        {



            // 数据库连接
            DBhelper sqlhelper = new DBhelper();
            //创建DataSet对象
            DataSet reader = sqlhelper.GetDataSet("select b.Productcode as 'Productcode' , b.Part as 'Part' ,b.Pm as 'Pm',b.Vollage as 'Vollage',b.Colour as 'Colour',b.SAP as  'SAP',b.Type as 'Type',b.Date as  'Date',b.Line as  'Line' from label b", "label");

            // 给显示控件赋值
            this.dataGridView1.DataSource = reader.Tables[0];
            // 外观自适应宽度
            for (int i = 0; i < dataGridView1.ColumnCount; i++)
            {
                dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;//自适应列宽
            }
            //-------------------------------------------------连接-------------------------------------------------------------------------

        }

        private void button4_Click(object sender, EventArgs e)
        {
            // 数据库连接
            DBhelper sqlhelper = new DBhelper();

            // sql语句
            string sql = " update label set  Productcode  ='" + textBox1.Text + "',Part='" + textBox2.Text + "',Pm='" + textBox3.Text + "',Vollage='" + textBox4.Text + "',Colour='" + textBox5.Text + "',SAP='" + textBox6.Text + "',Type='" + textBox7.Text + "',Date='" + textBox8.Text + "',Line='" + textBox9.Text + "'where Productcode  ='" + textBox1.Text + "'";


            try
            {
                //创建DataSet对象
                sqlhelper.GetSqlCom(sql);
                dataShow();
            }
            catch
            {
                MessageBox.Show("修改失败");
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // 获取选中行的某个数据
            int rowindex = e.RowIndex;
            try
            {
                textBox1.Text = dataGridView1.Rows[rowindex].Cells[0].Value.ToString();
                textBox2.Text = dataGridView1.Rows[rowindex].Cells[1].Value.ToString();
                textBox3.Text = dataGridView1.Rows[rowindex].Cells[2].Value.ToString();
                textBox4.Text = dataGridView1.Rows[rowindex].Cells[3].Value.ToString();
                textBox5.Text = dataGridView1.Rows[rowindex].Cells[4].Value.ToString();

                textBox6.Text = dataGridView1.Rows[rowindex].Cells[5].Value.ToString();
                textBox7.Text = dataGridView1.Rows[rowindex].Cells[6].Value.ToString();
                textBox8.Text = dataGridView1.Rows[rowindex].Cells[7].Value.ToString();
                textBox9.Text = dataGridView1.Rows[rowindex].Cells[8].Value.ToString();
            }
            catch
            {
                MessageBox.Show("赋值异常");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 数据库连接
            DBhelper sqlhelper = new DBhelper();

            // sql语句
            string sql = "INSERT INTO `label` VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "')";


            try
            {
                //创建DataSet对象
                sqlhelper.GetSqlCom(sql);
                dataShow();
            }
            catch
            {
                MessageBox.Show("插入数据异常");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            // 数据库连接
            DBhelper sqlhelper = new DBhelper();

            // sql语句
            string sql = " delete from label where Productcode='" + textBox1.Text + "'";

            try
            {
                //创建DataSet对象
                sqlhelper.GetSqlCom(sql);
                dataShow();
            }
            catch
            {
                MessageBox.Show("删除失败");
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            {
                try
                {


                    btFormat = btApp.Formats.Open(AppDomain.CurrentDomain.BaseDirectory + "小包标签1.btw", false, "");
                    btFormat.SetNamedSubStringValue("Productcode", textBox1.Text);
                    btFormat.SetNamedSubStringValue("Part", textBox2.Text);
                    btFormat.SetNamedSubStringValue("Pm", textBox3.Text);
                    btFormat.SetNamedSubStringValue("Vollage", textBox4.Text);
                    btFormat.SetNamedSubStringValue("Colour", textBox5.Text);

                    btFormat.SetNamedSubStringValue("SAP", textBox6.Text);
                    btFormat.SetNamedSubStringValue("Type", textBox7.Text);
                    btFormat.SetNamedSubStringValue("Date", textBox8.Text);
                    btFormat.SetNamedSubStringValue("Line", textBox9.Text);


                    btFormat.PrintOut(true, false); //第二个false设置打印时是否跳出打印属性
                    btFormat.Close(BarTender.BtSaveOptions.btSaveChanges);//退出是是否保存标签
                }
                catch
                {
                    MessageBox.Show("打印失败");
                }

            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
         
       

         

            this.DialogResult = DialogResult.OK;

        
    }
    }
}

到了这里,关于C#winform连接MYSQL数据库斑马打印机打印标签的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MySQL数据库,JDBC连接数据库操作流程详细介绍

    在学完 MySQL 和 Java 后,我们通常会尝试使用 Java编译器 连接 MySQL数据库,从而达到使用编译器来操作数据库的效果。连接的这个过程会用 JDBC 相关知识,因此我把 JDBC 包的下载及导入流程,以及 JDBC 的使用流程整理下来分享给大家。 目录 1. 啥是JDBC? 2. JDBC依赖包 2.1 依赖包

    2024年02月06日
    浏览(76)
  • Mysql查询数据库连接状态及连接信息

    使用MySQL时,需要了解当前数据库的情况,例如当前的数据库大小、字符集、用户等等。下面总结了一些查看数据库相关信息的命令 查看显示所有数据库 查看当前使用的数据库 查看数据库使用端口 查看当前数据库大小 例如,我要查看INVOICE数据库的大小,那么可以通过下面

    2024年02月11日
    浏览(41)
  • mysql面试题30:什么是数据库连接池、应用程序和数据库建立连接的过程、为什么需要数据库连接池、你知道哪些数据库连接池

    该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 数据库连接池是一种用于管理和复用数据库连接的技术。它是在应用程序和数据库之间建立一组数据库连接,并以池的形式存储起来,每当应用程序需

    2024年02月07日
    浏览(44)
  • Python 连接 MySQL 数据库

    在实际数据分析和建模过程中,我们通常需要从数据库中读取数据,并将其转化为 Pandas dataframe 对象进行进一步处理。而 MySQL 数据库是最常用的关系型数据库之一,因此在 Python 中如何连接 MySQL 数据库并查询数据成为了一个重要的问题。 本文将介绍两种方法来连接 MySQL 数据

    2024年02月16日
    浏览(40)
  • c++ 连接mysql数据库

            使用vs2019对window11中的数据库进行连接 1. 配置连接环境         首先需要把mysql中的头文件和库文件放入到c++项目工程中 1.打开安装MySQL的目录,在windows系统中如果是默认路径,应该和我的是一样的:C:Program FilesMySQLMySQL Server 8.0 2.找到include,和lib文件,inclu

    2024年02月02日
    浏览(31)
  • scala连接mysql数据库

    scala中通常是通过JDBC组件来连接Mysql。JDBC, 全称为Java DataBase Connectivity standard。 加载依赖 其中包含 JDBC driver 1.1 spark组件直接连接(推荐) 通过spark.read直接连接,直接得到dataframe 注意:driver的类名根据不同的JDBC版本不同,早一些的版本为 com.mysql.jdbc ,而不是 com.mysql.cj.jdbc

    2024年02月13日
    浏览(26)
  • Java连接mysql数据库

    java连接mysql大致需要这六步: 导入驱动包 :这里我使用的是mysql-connector-java-8.0.17.jar( 点击下载 ),这个包连接mysql5.6,5.7,8.0版本都没问题。 Class.forName(\\\"com.mysql.cj.jdbc.Driver\\\"); url和账户名密码 JDBC连接串: jdbc:mysql://地址:端口/数据库 获取连接 : DriverManager.getConnection(url, user

    2024年02月02日
    浏览(39)
  • C++连接mysql数据库

    目录 一、准备 二、读取数据 三、修改数据 参考博客 mysql安装及操作 首先在本地下载mysql数据库,或者使用在线数据库,在数据库中创建一个表,往表里填入数据,不然无法读取到数据。运行代码前,将libmysql的静态库和动态库拷贝到代码路径,c++工程的包含路径配置成mys

    2024年02月15日
    浏览(39)
  • C#控制台连接Mysql数据库,有配置数据库连接字符串的配置文件

    实现功能 读取. .txt 中的配置文件,来初始化连接字符串 让连接字符串的配置文件不存在会主动创建默认的连接字符串 注意点: 需要引用Newtonsoft 使用mysql

    2024年02月10日
    浏览(39)
  • PHP之 连接MySql数据库

    上一节已经成功配置了php+mysql开发环境( https://mp.csdn.net/mp_blog/creation/editor/129432310), 下面将进行实战连接数据库 一,打开sublime3编辑器,配置php开发环境 1.1 在网站根目录下新建php项目文件夹,存放php文件 1.2 安装Package Control,按下ctrl+shift+p,调出输入框输入Package Control,

    2024年02月02日
    浏览(42)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包