asp.net中的DataGrid视图不显示数据

时间:2010-10-03 18:07:46

标签: asp.net sql-server

 
I want to dispaly column in datagrid view using custom query statement
but i want to send value to parametrized data in query 
how can i do this ?
my code is below  
select c.customer_id, c.customer_first_name, c.customer_last_name, c.customer_address, c.account_number, c.account_type, a.account_balance, t.transfer_amount_balance, t.samebank_transfer_id, t.account_number_same_bank, t.transferdatetime FROM customer_details c join account_details a on c.account_number = a.account_number join transactions_details t on a.account_number = t.account_number where c.customer_id = 'cus0010' and a.account_number = 'acc0010' this above code working properly in sql server 2005
I want to dispaly column in datagrid view using custom query statement
but i want to send value to parametrized data in query 
how can i do this ?
my code is below  
but the code below which is modified as per asp.net page for grid view is not showing
any result
select 
c.customer_id,
c.customer_first_name,
c.customer_last_name,
c.customer_address,
c.account_number,
c.account_type,
a.account_balance,
t.transfer_amount_balance,
t.samebank_transfer_id,
t.account_number_same_bank,
 t.transferdatetime
FROM customer_details c join account_details a on c.account_number = a.account_number 
join transactions_details t on a.account_number = t.account_number where
c.customer_id = 'Label1.Text' and a.account_number = 'Label2.Text'

2 个答案:

答案 0 :(得分:1)

使用:
string.Format("c.customer_id = '{0}' and a.account_number = '{1}'", Label1.Text, Label2.Text);

考虑这个问题:
string query = "insert into TestTable (Column1, Column2) values (@p1, @p2)";

p1& p2是参数,以便设置您需要使用的参数的值:

queryParameters[0] = new SqlCeParameter("p1", SqlDbType.NVarChar);
queryParameters[0].Value = Label1.Text;
queryParameters[1] = new SqlCeParameter("p2", SqlDbType.NVarChar);
queryParameters[1].Value = Label2.Text;
SqlCeCommand command = new SqlCeCommand(query);
command.Parameters.AddRange(queryParameters);

当向导生成查询时,您需要使用customer_ID和account_number的占位符/参数,并使用参数设置它们的值。

编辑:
为了使向导创建一个在查询中使用的参数,添加一个?在查询构建器向导的筛选器列中。

答案 1 :(得分:0)

好吧,我可能会误解,但是......你实际上并没有发送字符串'Label1.Text',我猜?您应该发送文本框的值,如下所示(如果您将SQL构建为字符串?):

... [SQL] ... +“c.customer_id ='”+ Label1.Text +“'”...... [SQL的其余部分]