日期:2014-05-18  浏览次数:20797 次

[求助] 晕,有种想吐血的感觉!!!(没分了...)
额....没分了,大侠们当作作好事吧。


一个win窗体中:

存储过程:
SQL code

CREATE   PROCEDURE   getallczyinfo 
( 
@sale_id   char(10)   , 
@sale_name   char(10), 
@sale_jg   char(10) 
) 
  AS
declare @condition varchar(400)
     set @condition=''
 if(rtrim(@sale_id)!='')
    begin
           set @condition=@condition+' and sale_id='''+@sale_id+''''
    end
 if(rtrim(@sale_name)!='')
    begin
           set @condition=@condition+' and sale_name='''+@sale_name+''''
    end
 if(rtrim(@sale_jg)!='')
    begin
           set @condition=@condition+' and sale_jg='''+@sale_jg+''''
    end
declare @select1 varchar(2000)

   set @select1='select   salepeople.sale_id   as   销售员编号,salepeople.sale_name   as   销售员姓名,salepeople.sale_sex   as   销售员性别, 
salepeople.sale_age   as   销售员年龄,   salepeople.sale_jg   as   销售员籍贯,salepeople.sale_xl   as   销售员学历,   
salepeople.sale_call   as   销售员电话,salepeople.sale_zhz   as   销售员住址,   salepeople.sale_xst   as   销售员柜台   from   salepeople   
  where sale_id!=''-1'''
    exec(@select1+@condition)
GO



代码是:
C# code

namespace openjjsys
{
    public partial class salepeoplemanage : Form
    {
        public salepeoplemanage()
        {
            InitializeComponent();
        }

        private SqlConnection mycn;
        private SqlCommand mycmd;
        private SqlDataAdapter myda;
        private DataSet myds;
      
        private void salepeoplemanage_Load(object sender, EventArgs e)
        {
                mycn = new SqlConnection();
                mycn = new SqlConnection("server=localhost;uid=sa;pwd=;database=openjjsys;");
                myds = new DataSet();
                mycmd = new SqlCommand();
                mycmd.Connection = mycn;
                mycmd.CommandType = CommandType.StoredProcedure;
                mycmd.CommandText = "getallczyinfo";
                
                mycmd.Parameters.Add(new System.Data.SqlClient.SqlParameter ("@sale_id",System.Data.SqlDbType.Char,10,"sale_id"));
                mycmd.Parameters.Add(new System.Data.SqlClient.SqlParameter ("@sale_name", System.Data.SqlDbType.Char, 10, "sale_name"));
                mycmd.Parameters.Add(new System.Data.SqlClient.SqlParameter ("@sale_jg", System.Data.SqlDbType.Char, 10, "sale_jg"));
                myda = new SqlDataAdapter();
                myda = new SqlDataAdapter("getallczyinfo", mycn);

                myda.SelectCommand = mycmd;
                mycmd.Parameters["@sale_id"].Value = "%";
                mycmd.Parameters["@sale_name"].Value = "%";
                mycmd.Parameters["@sale_jg"].Value = "%";
                myda.Fill(myds, "salepeople");
                dataGridView1.DataSource = myds;
                dataGridView1.DataMember = "salepeople";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                myda.SelectCommand.Parameters["@sale_id"].Value = textBox1.Text;
                myda.SelectCommand.Parameters["@sale_name"].Value = textBox2.Text;
                myda.SelectCommand.Parameters["@sale_jg"].Value = comboBox1.SelectedItem;
                myds.Tables["salepeople"].Clear();
                myda.Fill(myds, "salepeople");
            }
            catch (SqlException ee) { MessageBox.Show(ee.Message); }
        }

    }
}



这个样子就可以....于是我就想了,我在新建一个win窗体....只做少少的改动。

存储过程:
SQL code

                    香港全能空间 免费试用15天香港高速云虚拟主机PHP/ASP/NET送MSSQL和MYSQL