Ciao a tutti, ho la necessità di creare un Windows Form in Visual c# che contenga un database sqlserver , le cui colonne devono essere popolate da valori ottenuti tramite Query da un Database Mysql .
Fin ora ho creato sia il mio database Mysql su un server sia il mio database sqlserver
Riesco a connettermi al database Mysql e tramite query al db riesco ad inserire i valori dentro una listbox con il seguente codice
private void botton_Click(object sender, EventArgs e)
{string host = "xxx.xxx.xxx.xxx";
string database = "test";
string user = "user";
string password = "pass";
// string strSQL = "SELECT * FROM jos_sobi2_fields_data";
string MyConString = "Data Source=" + host + ";Database=" +
database + ";User ID=" +
user + ";Password=" + password;
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "SELECT A.title FROM jos_sobi2_item A, jos_sobi2_cat_items_relations B WHERE A.itemid=B.itemid AND B.catid=2";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
//MessageBox.Show("fdsf:" + x);
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++){
thisrow += Reader.GetValue(i).ToString() + ",";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
ora per inserire i valori dentro le colonne avevo pensato a qualcosa del genere
artistiDataGridView.CurrentCell = artistiDataGridView.Rows.Cells[1];
artistiDataGridView.CurrentCell.Value += Reader.GetValue(i).ToString() + ",";
Ma cosi facendo mi scrive tutti i valori ottenuti dentro la prima cella
Vi prego aiutaremi.
|