Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using this code in code behind file.
VB
Imports System.Data
Imports System.Data.Sqlclient

Partial Class ProductDetails
  Inherits System.Web.UI.Page

  Public strProductCode As String
  Public ConnectionString As String

  Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    strProductCode = Request.QueryString("type")
    ConnectionString = System.Configuration.ConfigurationManager.AppSettings("StagingConnectionString")

    Me.SqlDataSource1.ConnectionString = ConnectionString
    'Me.SqlDataSource1.SelectCommand = "SELECT * FROM tblFinishedProd WHERE (strProductCode = " & strProductCode & ")"

'this worked fine.
'now I want run that code by using SP

Me.SqlDataSource1.SelectCommand = "spGetProductDetails"
Me.SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure

'SqlDataSource1: stored proc paramter = strProductCode
   
'How to set the paramter for the SqlDataSource ????

    Me.SqlDataSource1.DataBind()
End Sub

SQL
--** Stored Proc (piece) **
alter PROCEDURE spGetProductDetails (@ProductCode as nvarchar(50))


Thx for you help!
Posted
Updated 22-Apr-13 1:56am
v4
Comments
Karthik Harve 22-Apr-13 7:56am    
[Edit] pre tags added.

Use like this

C#
sqlDataSource1.SelectCommand = "spGetProductDetails";
sqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
 
sqlDataSource1.SelectParameters.Add("code",TypeCode.String, "1");
sqlDataSource1.SelectParameters[0].Direction =ParameterDirection.Input; 
 
GridView1.DataSource = sqlDataSource1;
GridView1.DataBind();




Check this for more info...
http://forums.asp.net/t/1115044.aspx/1[^]
 
Share this answer
 
v2
C#
cmd.Parameters.AddWithValue("@parameterName",parameterValue);
 
Share this answer
 
hi,

SqlCommand sqlCmd = new SqlCommand("[usp_PBCustomWorkFlowJobsList_GroupBy]", sqlcon);
       sqlCmd.CommandType = CommandType.StoredProcedure;
       SqlDataAdapter dataAdapter = new SqlDataAdapter();
       SqlParameter[] sqlparam = new SqlParameter[1];
       sqlparam[0] = new SqlParameter("UserId", SqlDbType.Int);
       sqlparam[0].Value = 148291;
       sqlCmd.Parameters.Add(sqlparam[0]);

or
con.Open();
           SqlCommand cmd = new SqlCommand("sp_questions", con);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add(new SqlParameter("@question", "sai"));
           cmd.Parameters.Add(new SqlParameter("@answer", 2));
           cmd.Parameters.Add(new SqlParameter("@option1", "saddf"));
           cmd.Parameters.Add(new SqlParameter("@option2", "sagdf"));
           SqlDataReader rdr = cmd.ExecuteReader();
           con.Close();
 
Share this answer
 
v2
C#
string str = DropDownList1.SelectedItem.ToString();
        Session["tblnm"] = str;
        SqlDataSource1.SelectCommand = "myarea1";
        SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        SqlDataSource1.SelectParameters.Add("tablename", TypeCode.String, str);
        // SqlDataSource1.SelectParameters[0].Direction = ParameterDirection.Input;
 
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