2012-10-04 95 views
1

保護小組的Page_Load(BYVAL發件人爲對象,BYVALË作爲System.EventArgs)把手Me.Load必須聲明標量變量 「@user_code」 中參數化查詢

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 
+0

是爲你工作? –

+0

檢查結束代碼幫助您解決問題 –

+0

您的問題是什麼? – Jodrell

回答

2

代碼,用於將參數的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"); 

附加參數,你的數據適配器對象這樣

da.Parameters.Add(param) 

這是缺少在代碼

MSDN:Using Parameters with a DataAdapter

+0

無法解析符號參數。我的問題仍然沒有解決。 –

+0

@AdityaPratapSingh - 檢查msdn鏈接,您可以在其中找到示例如何將參數添加到dataadapter .... –