Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
CREATE PROCEDURE [dbo].[sp_GetUserDetail]
    @userId INT
AS
BEGIN
    SELECT
        [dbo].[Account].[userName] AS 'User',
        [dbo].[Employee].[Email] AS 'Send Mail'
    FROM
        [dbo].[Account]
    INNER JOIN
        [dbo].[Employee]
    ON
        [dbo].[Employee].[User_Id] = [dbo].[Account].[ID]
    WHERE
        [dbo].[Account].[ID] = @userId
END


I tried this
1 connect in SQL Database.
C#
Con.open()
SqlCommand cmd = new SqlCommand("sp_GetUserDetail", con)

how do i retrive details in form, as per above stored procedure.

What I have tried:

SqlConnection con = new SqlConnection("Data Source=ghrt\\se=CSharpUserLogin; Integrated Security=true");
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_GetUserDetail", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@userId" , '"+txtId.Text+"'  ));
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataTable dt = new DataTable();
            sda.Fill(dt);
            BindingSource bs = new BindingSource();
            bs.DataSource = dt;
            dgvEmployee.DataSource = bs;
            sda.Update(dt);
Posted
Updated 30-Dec-21 6:57am
v6
Comments
[no name] 29-Dec-21 21:44pm    
There's a part where you "submit" the command.

1 solution

You can easily answer this yourself. Read the documentation on SqlCommand[^], especially the Properties of SqlCommand, like CommandType[^], which takes a CommandType[^] enum value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900