Wednesday, March 21, 2012

please Help me find out a way!

I want a client to enter a 'key' in a textbox and click a button. then the entered value will be used to search a table in the MS-SQL database. The corresponding value found from that table will be used to search a second table. Data found from the second table will be bounded to the datagrid control at the page where the client entered the 'key'. What will be the way to achieve this? What will be the SQL command??

I'm not sure if I'm able to describe the problem. I'm a new user of ASP.NET. So please help.

Ishtiaque.

A stored procedure like this will work:

CREATE PROCEDUREdbo.Example
@.key1varchar(255)
AS
DECLARE@.key2varchar(255)
SELECT@.key2 = key2columnFROMTable1WHEREkey1column = @.key1
--The select below will return your results so you can bind to your grid:
SELECT*FROMTable2WHEREkey2column = @.key2


Thank you Sharbel_.

I made a stored procedure as you suggested and used it by a 'drag and drop' method in my webform. But as I mentioned I am a novice user of ASP.NET, could not utilize the sqlConnection or sqlCommand that resulted of doing so. Would you please let me know how to do so?

Thanks in advance.


Hi,

using System.Data.SqlClient; at the top in the .cs file

Create the connection and the command objects in the page_load or in the button click as

SqlConnection sqlcn =new SqlConnection(connectionString);

sqlcn.Open();

//creating and initialising a command object

SqlCommand sqlcm =new SqlCommand();

sqlcm.Connection = sqlcn;

sqlcm.CommandType = CommandType.StoredProcedure;

sqlcm.CommandText = StoredProcedure name;

sqlcm.ExecuteNonQuery();

HTH.

0 comments:

Post a Comment