Well, I'm new to programming language, I need some help. I'm trying to call the database in combobox with select, but I'm not able to do a function that when I click OK, it shows me the answer of what I selected. I need that help.
using System;
using System.Data.OleDb;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Instanciando conexao e comand do SQL
SqlConnection sql = new SqlConnection("Password=xxxxxxxxxx;Persist Security Info=True;User ID=xxxxxxInitial Catalog=BD_Testes;Data Source=xx.xxx.xx.xx");
SqlCommand comand = null;
SqlDataAdapter adapter = null;
//Dataset é uma tabela em memoria
DataSet ds = new DataSet();
//Abrindo conexao com o banco
sql.Open();
//Defino o comando que será executado
comand = new SqlCommand();
comand.CommandText = "select ccNomeFisicoArquivo FROM tbArquivoImportado";
comand.Connection = sql;
//Instancio o adapter, passando comand como parametro.
//O resultado do select será atribuido ao adapter, que irá preencher o dataset com o resultado
//Dataset é uma tabela que fica na memoria.
adapter = new SqlDataAdapter(comand);
adapter.Fill(ds);
//Para cada linha da tabela no dataset, preencho o combobox
foreach (DataRow row in ds.Tables[0].Rows)
{
comboBox1.Items.Add(row["ccNomeFisicoArquivo"]);
}
//Sempre fechar a conexao
sql.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
List<int> listaDosIdsNaGrid = new List<int>();
//AQUI EU PASSO P GRID O ITEM DA COMBO
dataGridView1.Rows.Add(comboBox1.SelectedText);
listaDosIdsNaGrid.Add((int)comboBox1.SelectedValue);
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
}
}
}
The combobox is funfando, I need to get the item from the combobox and when I click "OK" it will appear the result of the select that I give in the item