本文介绍了在组合框中选择项目时,无法在文本框中获取相关数据?下面是代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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();
        }
    }
  }

推荐答案

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

dset.Tables[0].Rows[0]["Make"].ToString();

右键单击在quickwatch上

right click on quickwatch



这篇关于在组合框中选择项目时,无法在文本框中获取相关数据?下面是代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:54