vb 连接 access

Private Sub Command1_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim connstr As String
Dim sql As String
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\2.mdb;"
conn.Open constr
sql = "select * from 认定 where nno='" & Text1.Text & "'"
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
Text2.Text = sql
 If Not rs.EOF Then
        Text2.Text = rs.Fields("nid")
 Else
         MsgBox "数据不存在!"
         
 End If
    rs.Close
    conn.Close
End Sub

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Data.SqlClient; using System.Text; using MySql.Data; using MySql.Data.MySqlClient; //本程序的功能是实时从mysql中读取一条记录中的一个字段,插入到sqlserver 中,经过长时间的运行,基本无错了, 而这数据同步,目前没有实时性强的软件,至少1分钟,太久了,自己写了一个, //可以自己设置同步时间,字符连接串等,给了源码,而且对程序进行了很多优化 容错性很强,懂点程序的 就可以直接修改源码 就可以用了。由于没有时间按做界面,只能自己修改了,不过已经很稳定了,为了给大家提供点方便,免得还去查大量的资料。 namespace tool { public partial class Form1 : Form { public string mysql_Conn = "Database='cmccbbs';Data Source='211.139.22.124';UserId='cmcc';Password='CMCC2014cmcc2014';charset='utf8';pooling=true"; public string mysql_sql = "select max(id) from pre_sms_tempsend"; // public string sql_server_Conn = "Data Source=lei; DataBase=test; User=sa;PWD=123456"; 211.222.229.124 public string id, phone, verify, last_id; SqlConnection my_sql_con; MySqlConnection con; MySqlCommand cmd; DataSet ds; public string sql_server_Conn = "Data Source=222.85.144.112,14444; DataBase=DB_CustomSMS; User=sms;PWD=sms2014"; // public string sql_sql = "select max(id) from pre_sms_tempsend"; MySqlDataAdapter md; public int ii = 0; public Form1() { InitializeComponent(); timer1.Interval = 1000; //连接mysql con = new MySql.Data.MySqlClient.MySqlConnection(mysql_Conn); con.Open(); cmd = new MySqlCommand("select * from pre_sms_tempsend order by id desc limit 1", con); cmd.Connection = con; md = new MySqlDataAdapter(); ds = new DataSet(); //这样做避免一直new,导致内存泄露 } private void button1_Click(object sender, EventArgs e) { if (button1.Text == "start") { timer1.Enabled = true; button1.Text = "stop"; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值