日期:2014-05-17  浏览次数:21117 次

为什么combobox.text获取不了值
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;

namespace WindowsFormsApplication8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string str = "Data Source=192.168.1.1;Database=cbyy;Uid=his;Pwd=samanagger";
            SqlConnection conn = new SqlConnection(str);
            string Sql = "select mc  from zd_yp order by mc";
            DataSet Ds = new DataSet();
            SqlDataAdapter Da = new SqlDataAdapter(Sql, conn);
            Da.Fill(Ds, "zd_ry");
            comboBox1.DataSource = Ds.Tables["zd_ry"];
            comboBox1.DisplayMember = "mc";
            comboBox1.ValueMember = "mc";
            comboBox1.SelectedValue = "mc";
        }

        public void button1_Click(object sender, EventArgs e)
        {
            string d1 = this.textBox1.Text + "-" + this.textBox2.Text + "-" + this.textBox3.Text;
            string d2 = this.textBox4.Text + "-" + this.textBox5.Text + "-" + this.textBox6.Text;
            string sql = mysql(d1, d2);
            string str = "Data Source=192.168.1.1;Database=cbyy;Uid=his;Pwd=samanagger";
            SqlConnection conn = new SqlConnection(str);
            DataSet Ds = new DataSet();
            SqlDataAdapter Da = new SqlDataAdapter(sql, conn);
            Da.Fill(Ds, " ");
            dataGridView1.DataSource = Ds.Tables[" "];
            textBox7.Text = sql;

        }