1

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim ds As DataSet = New DataSet()
    Dim param As SqlParameter = New SqlParameter("@user_code", SqlDbType.Char, 4)
    param.Value = "0016"
    Const sqlstr As String = "select sectors.sector_code,sector_name   from user_sectors inner join sectors on user_sectors.sector_code = sectors.sector_code  where user_code = @user_code  and sectors.sector_code not in ('z')"

    Dim da As SqlDataAdapter = New SqlDataAdapter(sqlstr, _con)
    da.Fill(ds)
    ddl.DataValueField = "sector_code"
    ddl.DataTextField = "sector_name"
    ddl.DataSource = ds.Tables(0)
    ddl.DataBind()

End Sub
2
  • check the aded code help you to resolve your issue Commented Oct 4, 2012 at 8:06
  • Essesntially, you declare an SqlParameter but you don't do anything with it. Your need to add it to an SqlCommand. Or just use EF or some other ORM. Commented Oct 4, 2012 at 8:23

1 Answer 1

2

Code for adding parameter to dataadapter

    SqlConnection conn = new SqlConnection("Data 
             Source=localhost;Database=Northwind;Integrated Security=SSPI");
  SqlCommand command = new SqlCommand("GetProducts", conn);
  command.CommandType = CommandType.StoredProcedure;
  command.Parameters.Add("@CategoryID", SqlDbType.Int).Value = 1;
  SqlDataAdapter adapter = new SqlDataAdapter(command);
  DataSet ds = new DataSet();
  adapter.Fill(ds, "Products");

add parameter to you data adapter object like this

da.Parameters.Add(param)

this is missing in your code

MSDN : Using Parameters with a DataAdapter

Sign up to request clarification or add additional context in comments.

2 Comments

cannot resolve symbol Parameter. my problem still not solved.
@AdityaPratapSingh - check the msdn link where you can find example how to add parameter to the dataadapter....

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.