Hej!
Jag ny på asp.net och jag har nu problem att uppdatera en tabell i en access databas.
Det jag inte förstår är varför det inte går. Får hela tiden felmeddelandet "Record can not update". Någon som kan se vad som spökar eller tipsa vad jag ska göra ... då blir jag jätteglad!
Att lägga till och visa ... inga problem men att uppdatera ... ;-(
//Annette
Imports System.Data
Imports System.Data.OleDb
Partial Public Class redigera_ny
Inherits System.Web.UI.Page
Dim objConn As New OleDb.OleDbConnection
Dim objCmd As New OleDb.OleDbCommand
Dim dtReader As OleDb.OleDbDataReader
Dim strConnString, strSQL As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/App_Data/kurser.mdb") & ";Jet OLEDB:Database Password=;"
objConn.ConnectionString = strConnString
objConn.Open()
If Not Page.IsPostBack() Then
ViewData()
End If
End Sub
Sub ViewData()
'*** DataTable ***'
Dim dtAdapter As OleDb.OleDbDataAdapter
Dim dt As New DataTable
strSQL = "SELECT * FROM Kursinfoblad WHERE ID = " & Request.QueryString("ID") & " "
dtAdapter = New OleDb.OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
Me.strRubrik.Text = dt.Rows(0)("Rubrik")
Me.strKursNr.Text = dt.Rows(0)("KursNr")
Me.strKursLangd.Text = dt.Rows(0)("KursLangd")
Me.strMalgrupp.Text = dt.Rows(0)("Malgrupp")
Me.strKursansvarig.Text = dt.Rows(0)("Kursansvarig")
Me.strKursadmin.Text = dt.Rows(0)("Kursadmin")
Me.strPris.Text = dt.Rows(0)("Pris")
Me.strMal.Text = dt.Rows(0)("Mal")
Me.strInnehall.Text = dt.Rows(0)("Innehall")
Me.strBeskrivning.Text = dt.Rows(0)("Beskrivning")
End If
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
strSQL = "UPDATE Kursinfoblad SET " & _
" Rubrik = '" & Me.strRubrik.Text & "' " & _
" ,KursNr = '" & Me.strKursNr.Text & "' " & _
" ,KursLangd = '" & Me.strKursLangd.Text & "' " & _
" ,Malgrupp = '" & Me.strMalgrupp.Text & "' " & _
" ,Kursansvarig = '" & Me.strKursansvarig.Text & "' " & _
" ,Kursadmin = '" & Me.strKursadmin.Text & "' " & _
" ,Kursadmin = '" & Me.strKursadmin.Text & "' " & _
" ,Pris = '" & Me.strPris.Text & "' " & _
" ,Mal = '" & Me.strMal.Text & "' " & _
" ,Innehall = '" & Me.strInnehall.Text & "' " & _
" ,Beskrivning = '" & Me.strBeskrivning.Text & "' " & _
" WHERE ID = '" & Request.QueryString("ID") & "' "
'Response.Write(strSQL)
objCmd = New OleDb.OleDbCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Me.pnlAdd.Visible = False
Try
objCmd.ExecuteNonQuery()
Me.lblStatus.Text = "Record Updated"
Me.lblStatus.Visible = True
Catch ex As Exception
Me.lblStatus.Text = "Record can not update"
End Try
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
End Class