How to link ComboBox with Database Values - I have two Errors
Hi, I have tried to link my combobox to the database values but, i have two errors wherefore, i need your help. I am using vb.net 2008 and 3.5 framework.
The code is below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace Csharptutorial10
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Blessed;Integrated Security=True;");
SqlCommand cmd = new SqlCommand();
SqlDataReader myReader;
public Form1()
{
InitializeComponent();
Fillcombo();
}
void Fillcombo()
{
try
{
cmd.CommandText = "select * from Employee;";
con.Open();
myReader = cmd.ExecuteReader();
while (myReader.Read())
{
string sFirstName = myReader.GetValues("FirstName");
comboBox1.Items.Add(sFirstName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void employeeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.employeeBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.blessedDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'blessedDataSet.Employee' table. You can move, or remove it, as needed.
this.employeeTableAdapter.Fill(this.blessedDataSet.Employee);
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void buttonAddString_Click(object sender, EventArgs e)
{
string sFirstName = firstNameTextBox.Text;
comboBox1.Items.Add(sFirstName);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
eIDTextBox.Text = comboBox1.Text;
}
}
}
Re: How to link ComboBox with Database Values - I have two Errors