Hi everyone,
i have the done following coding, unable to get the it working..
i have a Table with Id, Product, FolderPath.
i have a comboBox2 where i need two column of data from above table "Id" & "Product" to been shown in comboBox2. Now if i select a Row from comboBox2 i need the textBox1 and textBox2 to be filled with "Product" and "FolderPath" based on the comboBox2 selection.
Like even though the comboBox2 shows "Id" & "Product" internally the value has to be "Id".
Following are my code; can someone help me on this.
- using System;
- 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.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
-
-
-
- namespace WindowsFormsApp1
- {
- public partial class Main : Form
- {
- string connString;
- SqlConnection conn;
- public Main()
- {
- InitializeComponent();
- }
-
-
-
- private void Main_Load(object sender, EventArgs e)
- {
- connString = @"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=ifz001;";
- conn = new SqlConnection(connString);
- conn.Open();
- Load_Products();
- }
-
-
-
- void Load_Products()
- {
- try
- {
- SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM FileFolderPath", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
-
-
-
- for(int i = 0; i < dt.Rows.Count; i++)
- {
- comboBox2.Items.Add(dt.Rows[i]["Id"].ToString() + " | " + dt.Rows[i]["Product"].ToString());
-
-
-
-
- comboBox2.ValueMember = dt.Rows[i]["Id"].ToString();
- }
-
-
-
-
- }
- catch (Exception lp)
- {
- MessageBox.Show(lp.Message);
- }
- }
-
-
-
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
-
-
-
- var pix = "SELECT * FROM FileFolderPath WHERE Id = '" + comboBox2.ValueMember + "'";
- SqlCommand cmd = new SqlCommand(pix, conn);
- cmd.ExecuteNonQuery();
- DataTable dt = new DataTable();
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(dt);
- foreach(DataRow dr in dt.Rows)
- {
-
- PID.Text = dr["Product"].ToString();
- PPath.Text = dr["FolderPath"].ToString();
-
- }
-
-
-
-
-
-
- }
-
-
-
-