hi. I was trying to choose data from the combobox then When I choose something.. it will also generate the other data into the textbox.
I just wanted to choose a STUD_ID in the combobox and the fname and the lname should show in the textbox. actually.. I just did that.. but the error is I can only choose one time in the comboxBOX. then the "using System.Data.DataRowView;" will just appear in the comboBox... Someone might help me plsss... :(
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.OleDb;
using System.Data.SqlClient;
namespace LECTURE
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\lenovo\Desktop\LECTURE\LECTURE\Properties\LEESH.accdb";
conn.Open();
OleDbDataAdapter daa = new OleDbDataAdapter("SELECT * FROM STUDENT WHERE STUD_ID=" + "'" + comboBox1.Text + "'", conn);
DataSet dss = new DataSet();
daa.Fill(dss);
comboBox1.DataSource = dss.Tables[0].DefaultView;
DataView dv = (DataView)comboBox1.DataSource;
if (dv.Count > 0)
{
textBox1.Text = dv[0]["STUDFNAME"].ToString();
textBox2.Text = dv[0]["STUDLNAME"].ToString();
}
else
{
MessageBox.Show("No Reocrd hs been found", "Append");
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.GetBaseException().ToString(), "teka parang may mali?");
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\lenovo\Desktop\LECTURE\LECTURE\Properties\LEESH.accdb";
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM STUDENT", conn);
DataTable ds = new DataTable();
da.Fill(ds);
comboBox1.Text = "--Select--";
for (int i = 1; i < ds.Rows.Count; i++)
{
comboBox1.Items.Add(ds.Rows[i]["STUD_ID"]);
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.GetBaseException().ToString(), "Error In Connection");
}
}
}
}