Data Access Issues

  • Thread starter Thread starter Jerry Camel
  • Start date Start date
J

Jerry Camel

I'm trying to update a table on a SQL Server from a web page. I'm not having any problems reading the data, but I can't seem to update it. From the code below can someone please tell me what I'm missing? I'm sure I've kludged it up a bit with all my attempts. Thanks.

Dim sFileName As String
sFileName = Now.Millisecond & Now.Second & Now.Minute & Now.Hour & Now.Year & Now.Month & Now.Day

Dim sqlCnxn As New SqlConnection("user id=SomeUser;password=Pswd;data source=DATASERVER")
Dim daFiles As New SqlDataAdapter("SELECT * FROM FD_Files", sqlCnxn)
Dim dsFiles As New DataSet()
Dim custCB As SqlCommandBuilder = New SqlCommandBuilder(daFiles)

daFiles.Fill(dsFiles, "FD_Files")
Dim dr As DataRow = dsFiles.Tables(0).NewRow
dr("FileName") = Path.GetFileName(txtFile.PostedFile.FileName)
dr("ExpireTime") = Now.AddHours(24)
dr("PostedBy") = Session("UserAlias")
dr("HashName") = sFileName
dr("FileSize") = txtFile.PostedFile.ContentLength / 1024
dr("Description") = txtDescription.Text
dsFiles.Tables(0).Rows.Add(dr)
dsFiles.AcceptChanges()
daFiles.Update(dsFiles, "FD_Files")
 
It helps if you generate the SQL Commands after you add the rows to the table... I knew it had to be an easy fix.

Jerry
I'm trying to update a table on a SQL Server from a web page. I'm not having any problems reading the data, but I can't seem to update it. From the code below can someone please tell me what I'm missing? I'm sure I've kludged it up a bit with all my attempts. Thanks.

Dim sFileName As String
sFileName = Now.Millisecond & Now.Second & Now.Minute & Now.Hour & Now.Year & Now.Month & Now.Day

Dim sqlCnxn As New SqlConnection("user id=SomeUser;password=Pswd;data source=DATASERVER")
Dim daFiles As New SqlDataAdapter("SELECT * FROM FD_Files", sqlCnxn)
Dim dsFiles As New DataSet()
Dim custCB As SqlCommandBuilder = New SqlCommandBuilder(daFiles)

daFiles.Fill(dsFiles, "FD_Files")
Dim dr As DataRow = dsFiles.Tables(0).NewRow
dr("FileName") = Path.GetFileName(txtFile.PostedFile.FileName)
dr("ExpireTime") = Now.AddHours(24)
dr("PostedBy") = Session("UserAlias")
dr("HashName") = sFileName
dr("FileSize") = txtFile.PostedFile.ContentLength / 1024
dr("Description") = txtDescription.Text
dsFiles.Tables(0).Rows.Add(dr)
dsFiles.AcceptChanges()
daFiles.Update(dsFiles, "FD_Files")
 
Back
Top