Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server
I am using this code in code behind file.
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
--** Stored Proc (piece) **
alter PROCEDURE spGetProductDetails (@ProductCode as nvarchar(50))
 
Thx for you help!
Posted 22-Apr-13 0:30am
Edited 22-Apr-13 1:56am
v4
Comments
Karthik Harve at 22-Apr-13 7:56am
   
[Edit] pre tags added.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use like this
 
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[^]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

cmd.Parameters.AddWithValue("@parameterName",parameterValue);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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();
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 495
1 OriginalGriff 339
2 ChintanShukla 305
3 Richard Deeming 260
4 RyanDev 230
0 Sergey Alexandrovich Kryukov 8,768
1 OriginalGriff 7,387
2 CPallini 2,603
3 Richard MacCutchan 2,095
4 Abhinav S 1,893


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100