0

C# code :

string conn = @"Data Source=MRT\SQLSERVER;Initial Catalog=hrm;Persist Security Info=True;User ID=sa;Password=*******";

SqlConnection objsqlconn = new SqlConnection(conn);
objsqlconn.Open();

SqlCommand cmd = new SqlCommand("usp_fetchtest", objsqlconn);
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter lastname = cmd.Parameters.Add("@userid", SqlDbType.Int);
lastname.Value = 6;

SqlDataReader sdr;
sdr = cmd.ExecuteReader();

Stored procedure :

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[usp_fetchtest] 
    @userid int
AS
BEGIN
    SELECT firstName, lastName 
    FROM personal  
    WHERE personal.userid = @userid
END

How can I store this value in two array for firstname and lastname? So I can operate on that info in further project steps?

5
  • What have you tried? And what exactly do you mean by "...in two array". It all depends on how you want to access the data later. What kind of requirements you have... Commented Feb 27, 2020 at 19:20
  • i want to use that value for create pdf using iTextSharp. Commented Feb 28, 2020 at 6:17
  • can you help me @barns ? Commented Mar 1, 2020 at 16:42
  • Looks like you found your answer. Good Luck. Commented Mar 1, 2020 at 20:32
  • Thank you for giving your valuable time @Barns Commented Mar 2, 2020 at 5:50

1 Answer 1

1

You can iterate over the Read method:

while(sdr.Read())
{
    //Use get methods ex. sdr.GetString(columnIndex) or indexer sdr["firstName"] to 
    //extract data and place them in to other objects for further processing.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.