vs2013中c#如何连接MySQL数据库。

vs2013中c#如何连接MySQL数据库。,第1张

public static string strConnection = "Provider=Microsoft.Jet.OleDb.4.0Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~") + "数据库文件路径"

public System.Data.OleDb.OleDbConnection strconn = null

//获取datatable数据

public DataTable AExcuToTable(string sql)

{

DataTable dv = null

// System.Data.OleDb.OleDbConnection strconn=null

try

{

strconn = new System.Data.OleDb.OleDbConnection(strConnection)

if (strconn.State == ConnectionState.Closed)

strconn.Open()

System.Data.OleDb.OleDbDataAdapter oa = new System.Data.OleDb.OleDbDataAdapter(sql, strconn)

System.Data.DataSet ds = new DataSet()

oa.Fill(ds, "Table")

dv = ds.Tables["Table"]

}

catch

{

return null

}

strconn.Close()

return dv

}

对啊,链接成功后,你要想再获取mysql的字段,你还要用别的链接函数mysql_fetch_row()

给你一个我写的看看,

if(res)

{printf("select error:%s\n",mysql_error(&my_connection))

return 1

}

else

{

res_ptr=mysql_store_result(&my_connection)

printf( "receive data....\n")

while(sqlrow=mysql_fetch_row(res_ptr))

{

strcpy(record.sceneID,sqlrow[0])

strcpy(record.sceneName,sqlrow[1])

strcpy(record.sceneAddr,sqlrow[2])

fseek(fp,offset,SEEK_SET)

fwrite(&record, sizeof(RECORD),1,fp)/*.........*/

offset+= sizeof(RECORD)

memset(&record,0, sizeof(RECORD))//

}

printf( "write to file success\n")

mysql_free_result(res_ptr)

}

mysql_close(&my_connection)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10816302.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存