OK koden er oversættet nu, men jeg vil gerne bruge SqlDataReader, hvordan gøre jeg det?
Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs) Dim keyword As String = Request("k") If Not (keyword Is Nothing) AndAlso Not (keyword.Trim() = "") Then Dim sql As String = "select top 10* from WordList where word like '" + keyword.Trim().Replace("'", "''") + "%'" Dim conn As SqlConnection = New SqlConnection (ConfigurationSettings.AppSettings("connectionString")) conn.Open() Dim dt As DataTable = New DataTable () Dim command As SqlCommand = New SqlCommand (sql, conn) Dim adapter As SqlDataAdapter = New SqlDataAdapter (command) adapter.Fill(dt) conn.Close() For Each row As DataRow In dt.Rows Dim meaning As String = row("Meaning").ToString() Response.Write("<strong>" + row("Word").ToString() + "</strong> <i>" + row("Type").ToString() + "</i>: " + meaning + "<br>") Next End If End Sub
Dim con As SqlConnection = New SqlConnection ("server=ARNEPC2;Integrated Security=SSPI;database=Test") con.Open Dim cmd As SqlCommand = New SqlCommand ("SELECT * FROM T1", con) Dim rdr As SqlDataReader = cmd.ExecuteReader While rdr.Read Dim f1 As Integer = CType(rdr(0), Integer) Dim f2 As String = CType(rdr(1), String) ' brug f1 og f2 End While con.Close
det er sq ikke nemt når man ikke gør noget selv for sagen, hva'.
Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs) Dim keyword As String = Request("k") If Not (keyword Is Nothing) AndAlso Not (keyword.Trim() = "") Then Dim sql As String = "select top 10* from WordList where word like '" + keyword.Trim().Replace("'", "''") + "%'" Dim conn As SqlConnection = New SqlConnection (ConfigurationSettings.AppSettings("connectionString")) conn.Open()
Dim command As SqlCommand = New SqlCommand (sql, conn) Dim reader As SqlDataReader = command.ExecuteReader()
do whihe reader.Read() Dim meaning As String = reader("meaning").ToString() Response.Write("<strong>" + reader("Word").ToString() + "</strong> <i>" + reader("Type").ToString() + "</i>: " + meaning + "<br>") Next
hehehe cyberfessor...sorry men min kode virker allerede, sådan ser den ud...hmm den er ikke helt så flot men den virker:
Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)
Dim keyword As String = Request("k")
Dim sql As String = "SELECT * FROM nyhed where title like '%" & Replace(keyword, "'", "''") & "%'" Dim conn As SqlConnection = New SqlConnection ("Data Source=HOME; Initial Catalog=Testbase; User Id=sa; Password=;") conn.Open()
Dim dt As DataTable = New DataTable () Dim command As SqlCommand = New SqlCommand (sql, conn) Dim adapter As SqlDataAdapter = New SqlDataAdapter (command) adapter.Fill(dt) conn.Close()
For Each row As DataRow In dt.Rows Response.Write("<b>" + row("title").ToString() + "</b> - Author: <i>" + row("dato").ToString() + "</i> " + "<br>") Next
End Sub
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.