سلام
ببینید همچین چیزی مد نظرتون بود
دوتا جدول یکی ماشین و یک مدل ماشین رو توی دیتابیس گذاشتم
یه تایمر 2 تا تکست باکس
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Data.OleDb;
using System.Text;
using System.Windows.Forms;
namespace w3_farsi_combo
{
public partial class Form1 : Form
{
private static string conection1 = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+Application.StartupPath+@"\dbtest.accdb";
public Form1()
{
InitializeComponent();
}
OleDbConnection myConn = new OleDbConnection(conection1);
DataTable dt = new DataTable();
OleDbConnection cnn = new OleDbConnection(conection1);
private void Form1_Load(object sender, EventArgs e)
{
//cnn.Open();
//string query = "SELECT car FROM tbltest";
//OleDbCommand cmd = new OleDbCommand(query, cnn);
//OleDbDataReader reader = cmd.ExecuteReader();
//while (reader.Read())
//{
// comboBox1.Items.Add(reader["car"].ToString());
//}
//cnn.Close();
//comboBox1.SelectedIndex = 0;
DataTable table = new DataTable();
string sql = "Select car from tbltest";
try
{
cnn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(sql, cnn);
da.Fill(table);
table.Rows.Add("Select tbltest");
comboBox1.DataSource = table;
comboBox1.DisplayMember = "car";
comboBox1.ValueMember = "car";
comboBox1.SelectedValue = "Select car";
comboBox1.SelectedIndex = 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
timer1.Start();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == string.Empty)
{
return;
}
else
{
OleDbConnection cnn = new OleDbConnection(conection1);
OleDbCommand cmm = new OleDbCommand("select * from tbltest where ID=@id", cnn);
cmm.CommandType = CommandType.Text;
cmm.Parameters.AddWithValue("@id", textBox1.Text);
cnn.Open();
OleDbDataReader rdr = cmm.ExecuteReader();
if (rdr.Read())
{
textBox2.Text = rdr["saal"].ToString();
// comboBox1.Text = rdr["car"].ToString();
}
cnn.Close();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
textBox1.Text = "0";
}
if (comboBox1.SelectedIndex == 1)
{
textBox1.Text = "1";
}
if (comboBox1.SelectedIndex == 2)
{
textBox1.Text = "2";
}
if (comboBox1.SelectedIndex == 3)
{
textBox1.Text = "3";
}
if (comboBox1.SelectedIndex == 4)
{
textBox1.Text = "4";
}
}
}
}