C J
C J

Reputation: 417

DataGrid view in asp.net is not displaying data

 
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
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'

 the above is placed in my custom sql query section it
 is triggered by button click in my asp page or any other
 idea to display it will be welcomed 

Upvotes: 1

Views: 497

Answers (2)

sh_kamalh
sh_kamalh

Reputation: 3901

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

Consider this query:
string query = "insert into TestTable (Column1, Column2) values (@p1, @p2)";

p1 & p2 are parameters, in order to set the value for the parameters you need to use:

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

When the wizard is generating the query you need to use place holders/parameters for customer_ID and account_number and set their values by using parameters.

Edit:
In order to make the wizard create a parameter to use in the query, add a ? in the filter column in the query builder wizard.

Upvotes: 1

Rolle
Rolle

Reputation: 31

Well, I may misunderstand, but...you are not actually sending the string 'Label1.Text' I guess? You should send the value of the textbox, something like this (if you are building the SQL as a string?):

...[SQL]... + "c.customer_id = '"+ Label1.Text + "'" ...[rest of the SQL]

Upvotes: 0

Related Questions