我想使用c将mysql数据填充到gridview中#
查询使用nodejs+mysql,但使用c时会产生错误。
节点js代码:
app.get('/allhistorytalenta',function(req,res){
client.query("SELECT GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(mulai = ''',mulai,''', talenta, NULL)) AS ', QUOTE(mulai)) ORDER BY MULAI ASC ) INTO @sql FROM history_talenta; SET @sql = CONCAT('SELECT nip, nama, DATE_FORMAT(tgl_grade_terakhir,''%d-%m-%Y'') as tgl_grade_terakhir, ', @sql, ' FROM history_talenta GROUP BY nip'); PREPARE stmt FROM @sql; EXECUTE stmt;", function(err,rows_final){
res.render('pages/alltalenta',{ data2 : rows_final, data : req.session.user, datarole : req.session.role, moment : moment } );
console.log("Nilai Row Final : "+rows_final[3][1].nama);
});
});
这是我的c代码:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using MySql.Data.MySqlClient;
namespace DataGridView_CS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid()
{
string conString = @"Data Source=10.16.107.77;port=3306;Initial Catalog=sdmbook;User Id=root;password=xxxx";
using (MySqlConnection con = new MySqlConnection(conString))
{
using (MySqlCommand cmd = new MySqlCommand("SELECT GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(mulai = ''',mulai,''', talenta, NULL)) AS ', QUOTE(mulai)) ORDER BY MULAI ASC ) INTO @sql FROM history_talenta; SET @sql = CONCAT('SELECT nip, nama, DATE_FORMAT(tgl_grade_terakhir,''%d-%m-%Y'') as tgl_grade_terakhir, ', @sql, ' FROM history_talenta GROUP BY nip'); PREPARE stmt FROM @sql; EXECUTE stmt;", con))
{
cmd.CommandType = CommandType.Text;
using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
}
}
}
}
查询实际上是从数据进行转换:
分为:
如何使用c#和mysql以正确的方式执行我的查询?
谢谢您
暂无答案!
目前还没有任何答案,快来回答吧!