2014-04-25 4 views
0

나는 @Logins 매개 변수에 따라 결과를 반환하는 저장 프로 시저 AutoDeliveryReportsByUser을 가지고 있습니다. Radcombobox에서 db 컬럼 Emails의 모든 결과를 채우려고합니다. 필자는 열의 마지막 값을 가져 와서 레이블에 넣을 수 있지만 아무 것도 얻을 수 없지만 콤보 박스에서 아무 것도 얻을 수는 없습니다.VB/SQL 서버에서 ComboBox 채우기

Protected Sub ReportEmailList() 
      'sUser = Mid(HttpContext.Current.User.Identity.Name, InStr(HttpContext.Current.User.Identity.Name, "\", CompareMethod.Text) + 1) 
      sUser = "athens1" 
      Dim cmd As New SqlCommand("AutoDeliverReportsByUser", GetUDBSQLConn) 
      cmd.CommandType = CommandType.StoredProcedure 
      cmd.Parameters.Add("@Logins", SqlDbType.VarChar) 
      cmd.Parameters("@Logins").Value = sUser 
      cmd.Connection.Open() 

      Dim r As SqlDataReader = cmd.ExecuteReader 
      While r.Read 
       LblEmailList.Text = r("Emails") 
       RadCBEmailList.DataTextField = r("Emails") 

      End While 

      cmd.Connection.Close() 
      cmd.Dispose() 

     End Sub 

답변

0

나는 정확히 마지막에 처음부터 기록에 의해 기록을 읽는 동안 데이터

그 방법으로 그것을 읽는 독자를 사용하는 동안에 컨트롤을 바인딩하는 방법을 이해하지 않은 것으로 생각한다. 두 번째 포인트는 컨트롤을 바인딩하는 올바른 방법이 아닙니다. 여기에 귀하의 코드를 재 방문한다 : 그것은

대답으로 귀하의 요구 사항을 표시하십시오 일치

Protected Sub ReportEmailList() 
    'Create a new dataadapter and dataset which will be filled from datadapter. 
    Dim Da As New System.Data.SqlClient.SqlDataAdapter 
    Dim Ds As New System.Data.DataSet 
    Dim sUser = "athens1" 
    Dim cmd As New System.Data.SqlClient.SqlCommand("AutoDeliverReportsByUser", GetUDBSQLConn) 
    cmd.CommandType = Data.CommandType.StoredProcedure 
    cmd.Parameters.Add("@Logins", SqlDbType.VarChar) 
    cmd.Parameters("@Logins").Value = sUser 
    cmd.Connection.Open() 
    'Associate select command to dataadpter and then fill the databset 
    'now all your data are within dataset(DS) and you can access to each table where there's more than one with its name or by index 0 base as per example below 
    Da.SelectCommand = cmd 
    Da.Fill(Ds) 

    With RadCBEmailList 
     'Bind source data to rad component datasource 
     .DataSource = Ds.Tables(0) 
     'assgin to the textfield the column name needed 
     .DataTextField = "Emails" 
     'assing to the value field the column needed in example ID or any other one. 
     .DataValueField = "Emails" 
     'Call bind method to complete 
     .DataBind() 
     'Extra if you want to add a specific item to invite the customer to make something from the combo box not sure if it work with rad control it works fine with simple dropdownlist 
     '.Items.Insert(0, "Choose an email") it will be the first item into your control according previous comment 
    End With 

    End Sub 

경우

관련 문제