Kan någon se ett fel i nedanstående kod,Han skriver inte ut något. det var inte den det var fel på.Vad felet egentligen var vet jag inte, men jag byggde om den lite och då fungerade det bättre. Nedan finns en fungerande inläsning.Läsa in till DropDownList
<code>
Dim strDbConnect As String
strDbConnect = koppling(strDbConnect)
Dim myConnection As SqlConnection = New SqlConnection(strDbConnect)
Dim strSql As String
strSql = sqlGetCompanyNameToTidRapportering()
Dim myDataReader As SqlDataReader
Dim mcnCommand As SqlCommand = New SqlCommand(strSql, myConnection)
Try
myConnection.Open()
myDataReader = mcnCommand.ExecuteReader(CommandBehavior.CloseConnection)
ddlCompany.DataSource = myDataReader
ddlCompany.DataBind()
Catch ex As Exception
Response.Write("An error has occurred: " & ex.ToString())
Finally
If Not myDataReader Is Nothing Then
myDataReader.Close()
End If
ddlCompany.Items.Insert(0, "Select an Item")
ddlCompany.SelectedIndex = 0
End Try
</code>
<code>
<asp:DropDownList ID="ddlCompany" Runat="server" DataTextField="company" DataValueField="id" />
</code>Sv:Läsa in till DropDownList
<code>
Protected Sub btnTidRapportering_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTidRapportering.Click
'Visa datagriden och knapparna.
dgTidRapportering.Visible = True
bnArkiveraTidRapport.Visible = True
btnJusteraTidRapport.Visible = True
dgTidRapportering.DataSource = CreateDatasourceTidRapportering()
dgTidRapportering.DataBind()
tblLaggTillTidRapportering.Visible = True
Try
Dim strDbConnect As String
strDbConnect = koppling(strDbConnect)
Dim msnConnect As New Odbc.OdbcConnection(strDbConnect)
Dim strSql As String
strSql = sqlGetCompanyNameToTidRapportering()
Dim cmdSelectAll As New Odbc.OdbcCommand(strSql, msnConnect)
msnConnect.Open()
Dim objDataReader As Odbc.OdbcDataReader = cmdSelectAll.ExecuteReader
Dim ddlBox As New ListItemCollection
ddlBox.Add(New ListItem("Välj företag"))
ddlBox.Add(New ListItem)
While (objDataReader.Read())
ddlBox.Add(New ListItem(objDataReader("company").ToString()))
End While
ddlCompany.DataSource = ddlBox
ddlCompany.DataBind()
objDataReader.Close()
msnConnect.Close()
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
</code>