单击按钮时从mysql中恢复/获取数据 [英] Retrive/fetch data from mysql when a button is clicked

查看:94
本文介绍了单击按钮时从mysql中恢复/获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Forum,



我想要的是当用户点击按钮时从mysql数据库获取信息到文本框。



到目前为止,我已将它连接起来然后打开了。然后,您可以将文本框中的查询发送到数据库。



我在获取/重新获取数据和放入文本框或表格时遇到了麻烦。



到目前为止我有什么:



使用

Hello Forum,

What I want is to get info into to a textbox from the mysql database when the user clicks a button.

So far I have it so it connects and then opens up. Then you can send querys from the textbox to the database.

I'm having trouble in fetching/retriving data and putting into a textbox or table.

What I have so far:

Using

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace MySql::Data::MySqlClient;







查询




The Query

//Run The Query (Works like a charm)

private: System::Void RunQuery_Click(System::Object^  sender, System::EventArgs^  e) 
{
String^ SQLQuery = QueryBox->Text;
String^ connectionInfo = "datasource=localhost;port=3306;username=root;password=blacklegion;database=testing";
MySqlConnection^ conn = gcnew MySqlConnection(connectionInfo);
MySqlCommand^ connCMD = gcnew MySqlCommand(SQLQuery, conn);
MySqlDataReader^ dataReader;

try
{
	conn->Open();
	dataReader = connCMD->ExecuteReader();
}

catch(Exception^ex)
{
	MessageBox::Show(ex->Message);
}
//[End]
}





我试图让它工作的原因是我有一个Cpu Auth,我将与DB连接和在数据库中获取密钥。



我需要一些如何获取密钥并从数据库中读取它。





这是cpu auth



Reason why I'm trying to get it to work is that I have a Cpu Auth which i'm going to incorperate with the DB conneciton and fetch Keys within the db.

I need to some how fetch the keys and read it from the db.


This is the cpu auth

void CpuKeyCheck() 
    {
	BYTE hvCpuFuse1[0x10];
	BYTE cpuKeyBytes[0x10];
//Each CPUKEY need too add 0x0D, 0x57 and so on til all digits are in the text below
	//CPUKEY D33DC71DA1289D6E1E534BB54438AO8B - Developer
	
BYTE CPUKey[0x10] = 
{
0x22, 0x66, 0x39, 0xDC, 0x2D, 0xE7, 0x25, 0x9F0, 0x91, 0xE6, 0x88, 0xDC, 0x1E, 0xDD, 0x78, 0x5A 
};

	HvPeekBytes(0x20, cpuKeyBytes, 0x10);
	QWORD f1p1 = HvGetFuseLine(3) | HvGetFuseLine(4);
	QWORD f1p2 = HvGetFuseLine(5) | HvGetFuseLine(6);
	memcpy(hvCpuFuse1, &f1p1, 8);
	memcpy(hvCpuFuse1 + 8, &f1p2, 8);
	if (memcmp(hvCpuFuse1, cpuKeyBytes, 0x10) != 0)
    HalReturnToFirmware(HalResetSMCRoutine);
    if (memcmp(hvCpuFuse1, CPUKey, 0x10) != 0) 
    HalReturnToFirmware(HalResetSMCRoutine);
}









感谢先进的任何人帮帮我或指导我=],







爵士先生



我尝试了什么:



我试过google但我不知道我在做什么寻找,傻我知道,但这就是我需要帮助的原因。





Thanks in advanced for anyone to help me or guide me =],



Sir

What I have tried:

I've tried google but I don't know what I'm looking for , silly I know but it's why I need help.

推荐答案

我不确定你在寻找什么。我看到的一个复杂问题是你从一个文本框(QueryBox-> Text)获取SQL查询,这可能意味着你不知道在dataReader结果中会有多少列(或者它们是什么类型)



一般方法是



I'm not exactly sure what you're looking for. One 'complication' I see is that you're getting your SQL query from a ?textbox (QueryBox->Text) which may mean you dont know how many columns to expect back in the dataReader results (or what type they are)

The general approach would be

while (dataReader->Read())
{
  // do something with this row
}





然后你会使用(在while dataReader循环中) )





you would then use (within the while dataReader loop)

dataReader->GetString(column#)
dataReader->GetInt32(column#)





从列中获取值。



因此,回到最初的问题,dataReader有一个FieldCount属性,所以,这是列数,你可以循环遍历它们。 />


也许dataReader-> GetFieldType(#column)将会被使用,或者,将所有列作为字符串读取并将它们转换为int等,只需要



一个好的参考是 MySqlDataReader类 [ ^ ]



...这是你需要的那种帮助吗? (我不确定你的'cpu auth'有什么关联,如果有的话,你已经非常好地解释了它的连接/相关性)



To get the values from the columns.

So, going back to the original issue, the dataReader has a FieldCount property, so, that's the number of columns, you can for-loop through them.

Maybe dataReader->GetFieldType(#column) will be of use, or, read all the columns as strings and convert them to int etc only if you need to

A good ref is MySqlDataReader Class[^]

... is that the sort of help you need ? (I'm not sure what relevance your 'cpu auth' has if any, you havnt explained its connection/relevance terribly well)


我的解决方案:



My Solution:

private: System::Void GetTable_Button_Click(System::Object^  sender, System::EventArgs^  e)
{
	
	String^ connectionInfo = "datasource=localhost;port=3306;username=root;password=blacklegion;database=testing";
	MySqlConnection^ conn = gcnew MySqlConnection(connectionInfo);
	MySqlCommand^ connCMD = gcnew MySqlCommand("SELECT * FROM testing.cpu_keys;", conn);
	MySqlDataReader^ dataReader;

	conn->Open();
	dataReader = connCMD->ExecuteReader();
	
	while(dataReader->Read())
	{
    String^ vName;
    vName= dataReader->GetString("cpu_keys");
	comboBox1->Items->Add(vName); // <- Grabs the keys!
	//ReadTableBox->Text=(vName); // <- Only gets 1 though.
	}
// [End]
}


这篇关于单击按钮时从mysql中恢复/获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆