根据三个字段搜索数据 [英] search data according to three fields

查看:112
本文介绍了根据三个字段搜索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我的问题是
我创建了一个下拉列表,一个带有ajax calender exdender的文本框,一个带有文本框和搜索按钮的护照,它们是数据库表申请人
当我用绑定的选择下拉列表项填充这三个字段并选择日期并填充护照时,我单击搜索按钮,我的代码为波纹管(并且我还创建了一个视图,在该视图中,我根据匹配的名称将日期转换为vw_ApplicantDetails,转换日期列为v_ApplicationDate)VisaTypeNeeded_FK为外键

hey my problem is that
i create a dropdown , a text box with ajax calender exdender and a passport with textbox and a search button and their is a database table applicant
when i am fill this three fields with select dropdown item that is binded and select date and fill passport then i click on search button my code is bellow(and i have also create a view where i convert date according to match their name is vw_ApplicantDetails and convert date column is v_ApplicationDate)VisaTypeNeeded_FK is foreign key

string strSql = string.Empty;
       ddpl = visatype.SelectedItem.Value;
       strSql = "select * from vw_ApplicantDetails where AssignedTo = 'E' and     v_ApplicationDate='" + TextBox1.Text.ToString() + "' and Passport='" +  passport.Text.ToString() + "' and VisaTypeNeeded_FK='" +  visatype.SelectedItem.Value + "'";

       SqlCommand cmd = new SqlCommand(strSql);
       SqlDataAdapter adapter = new SqlDataAdapter(cmd);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "Applicant");
       GridView1.DataSource = ds.Tables["Applicant"];
       GridView1.DataBind();


它显示错误


it show the error

Fill: SelectCommand.Connection property has not been initialized.


请任何人帮助我..


please anyone help me..

推荐答案

您的连接字符串在哪里?
Where is your connection string?
SqlConnection cn = new SqlConnection(YourConnectionString)


尝试这样的事情:


Try something like this:

cn.open();//Open connection
SqlCommand cmd = new SqlCommand(strSql);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "Applicant");
GridView1.DataSource = ds.Tables["Applicant"];
GridView1.DataBind();
cn.close()//close connection


这篇关于根据三个字段搜索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆