19,500
社区成员
发帖
与我相关
我的任务
分享
using MySql.Data;
using MySql.Data.MySqlClient;
MySqlConnection mysqlcon;
MySqlCommand mysqlcom;
String connStr;
//1、
//connStr = "Persist Security Info=False;database=houseware;server=192.168.1.40;user id=sa;Password=123;";
2、
// connStr = "server=192.168.1.40;User Id=sa;Password=123; Persist Security Info=True;database=houseware;Character Set=gb2312;pooling=false";
//3、
connStr = "connection timeout=15; user id=sa; " +
"password=123; port=3306; database=houseware; data source=192.168.1.40; " +
"use compression=true; pooling=true; min pool size=3; max pool size=76";
mysqlcon = new MySqlConnection(connStr);
try
{
string sql = "select GoodCode from Storage where LableCode = '" + this.label1.Text.Trim() + "'";
mysqlcom = new MySqlCommand(sql, mysqlcon);
try
{
mysqlcom.Connection.Open();
}
catch (Exception ex1)
{
this.label2.Text = ex1.Message;
}
MySqlDataReader dr;
dr = mysqlcom.ExecuteReader();
if (dr.Read())
{
this.textBox1.Text = dr["GoodCode"].ToString();
this.button2.Tag = 0;
this.label2.Text = "";
}
else
{
this.label2.Text = "No data,Please add";
this.button2.Tag = 1;
}
dr.Close();
mysqlcom.Connection.Close();
}
catch (Exception ex)
{
this.label2.Text += ex.Message;
}