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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)