Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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 Comman;
using CRTReport;

namespace Spareage.Mail
{
    public partial class HardwareDetail : BaseForm
    {
        public HardwareDetail()
        {
            InitializeComponent();
        }
        DataTable dt;
        DataRow dr;
        //string code;
        string sWhere = "";
       
        SqlConnection objConn1 = new SqlConnection("Data Source=192.168.0.203;Initial Catalog=costing;User ID=sa;Password=****");
        SqlCommand comm = new SqlCommand();
       
        private void HardwareDetail_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'costingDataSet4.ITData' table. You can move, or remove it, as needed.
            this.iTDataTableAdapter.Fill(this.costingDataSet4.ITData);

            comboBox1.Items.Add("LCD");
            comboBox1.Items.Add("MONITOR");
            comboBox1.Items.Add("PRINTER");
            comboBox1.Items.Add("TONER");
            comboBox1.Items.Add("LAPTOP");
            comboBox1.Items.Add("SWITCH");
            comboBox1.Items.Add("SERVER");
            comboBox1.Items.Add("ADAPTER");
            comboBox1.Items.Add("CPU");
            comboBox1.Items.Add("THINCLIENT");
            comboBox1.Items.Add("HARD DISK");
            comboBox1.Items.Add("KEYBOARD");
            comboBox1.Items.Add("MOUSE");
            comboBox1.Items.Add("UPS");
            comboBox1.Items.Add("RAM");
            comboBox1.Items.Add("DATACARD");
            comboBox2.Items.Add("FAULTY");
            comboBox2.Items.Add("NEW USER");
            comboBox2.Items.Add("RELOCATION");
            comboBox3.Items.Add("Scrap");
            comboBox3.Items.Add("Under Use After Warrenty");
   
    //Connection string 

            string sqlStr = "SELECT Itemno FROM ITdata;";
            SqlDataAdapter dAdapter = new SqlDataAdapter(sqlStr, objConn1);

            DataTable dt = new DataTable();
            dAdapter.Fill(dt);
            
            this.comboBox4.DataSource = dt;
            this.comboBox4.DisplayMember = "Itemno";

        }
     }
        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sqlStr = "SELECT * FROM ITdata wehre Itemno=" + comboBox4.SelectedValue.ToString() + ";";
            //Instantiate a DataAdapter by passing the sqlStr and myConn. 
            SqlDataAdapter dAdapter = new SqlDataAdapter(sqlStr, objConn1);
            //Instantiate a DataSet
          DataSet  dset = new DataSet();
          DataTable dt = new DataTable();
            
            //fill the dataset
            dAdapter.Fill(dset);
            this.comboBox4.DataSource = ds;
            //DataBinding for the TextBox controls
            this.textBox3.Text = dset.Tables[0].Rows[0]["Itemno"].ToString();
            this.textBox1.Text = dset.Tables[0].Rows[0]["Make"].ToString();
        }
    }
  }
Posted
Updated 13-Jun-12 22:12pm
v4
Comments
VJ Reddy 14-Jun-12 4:11am    
Edit: pre tag for C# code added.

C#
this.textBox3.Text = ((dset.Tables[0].Rows[0])["Itemno"]).ToString();
this.textBox1.Text = ((dset.Tables[0].Rows[0])["Make"]).ToString();


i think this is the problem while debugging select
C#
dset.Tables[0].Rows[0]["Make"].ToString();
right click on quickwatch
 
Share this answer
 
v2
Comments
Master Vinu 14-Jun-12 4:24am    
.give below error
The multi-part identifier "System.Data.DataRowView" could not be bound.
objConn1.Open();
SqlDataAdapter d = new SqlDataAdapter("select Itemno from ITdata", objConn1);
DataSet dt = new DataSet();
d.Fill(dt);
comboBox4.DataSource = dt.Tables[0]; /// assing the first table of dataset
comboBox4.DisplayMember = "Itemno";
objConn1.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900