Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
让客户端创建自己的自定义MySQL查询,从vb.net中的数据库中获取数据_Mysql_Vb.net_Vb.net 2010 - Fatal编程技术网

让客户端创建自己的自定义MySQL查询,从vb.net中的数据库中获取数据

让客户端创建自己的自定义MySQL查询,从vb.net中的数据库中获取数据,mysql,vb.net,vb.net-2010,Mysql,Vb.net,Vb.net 2010,我想要一个程序,让用户创建他/她自己的查询,从数据库检索数据。实现这一任务的最佳方法是什么?任何链接或示例代码都将不胜感激。谢谢。我会选择: 创建一个表单,将其命名为formSample 添加一个文本框,将其命名为txbSample 添加datagridview,将其命名为dgvSample 添加一个按钮,命名为btnSample TXB示例将由客户端用于输入查询 btnSample是您放置代码的地方。 dgvSample是数据,并不推荐使用,但它只是用来显示检索到的数据 假设您已经连接到数据库

我想要一个程序,让用户创建他/她自己的查询,从数据库检索数据。实现这一任务的最佳方法是什么?任何链接或示例代码都将不胜感激。谢谢。

我会选择:

创建一个表单,将其命名为formSample
添加一个文本框,将其命名为txbSample
添加datagridview,将其命名为dgvSample
添加一个按钮,命名为btnSample

TXB示例将由客户端用于输入查询 btnSample是您放置代码的地方。 dgvSample是数据,并不推荐使用,但它只是用来显示检索到的数据

假设您已经连接到数据库,btnSample上的代码应该如下所示

注意:不是完整的代码

Dim sql As String
sql = txbSample.text

Using cmd As New MySqlCommand
   Try
      'open the connection here
      cmd.Connection = con
      cmd.CommandText = sql
      Dim dt As New DataTable
      da = New MySqlDataAdapter(cmd)
      da.Fill(dt)
      'close the connection here
      dgvSample.DataSource = dt
   Catch ex As Exception
      MessageBox.Show("Error while fetching data.")
      'close the connection here
   End Try
End Using


dt is a datatable where the data are stored. You should do something to be able to use it:)