类型' System.Data.SqlClient.SqlException'的例外情况发生在System.Data.dll但未在用户代码错误中处理?

时间:2016-04-21 14:02:43

标签: asp.net vb.net

当我尝试将以下信息插入到我的数据库中时,我得到了"类型' System.Data.SqlClient.SqlException'发生在System.Data.dll但未在用户代码错误中处理?"错误。

我的代码如下:

Imports System.Data.SqlClient
Partial Class SecurePages_AddBackup
Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim conn As SqlConnection
    Dim cmd As SqlCommand

    Dim customer As Integer
    Dim backupDate As String
    Dim Server As Integer
    Dim Status As String
    Dim Product As Integer
    Dim Details As String

    customer = ddlCustomer.SelectedValue
    backupDate = clDate.SelectedDate
    Server = DDLserver.SelectedValue
    Status = DDLStatus.Text
    Product = DDLproduct.SelectedValue
    Details = txtDetails.Text




    Dim cmdstring As String = "INSERT INTO Backup(CustomerID, Date, ServerID, Status, ProductID, Details) Values (@Customer, @BackupDate, @Server, @Status, @Product, @Details)"

    conn = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Backups.mdf;Integrated Security=True")
    cmd = New SqlCommand(cmdstring, conn)

    cmd.Parameters.AddWithValue("@Customer", customer)
    cmd.Parameters.AddWithValue("@BackupDate", backupDate)
    cmd.Parameters.AddWithValue("@Server", Server)
    cmd.Parameters.AddWithValue("@Status", Status)
    cmd.Parameters.AddWithValue("@Product", Product)
    cmd.Parameters.AddWithValue("@Details", Details)
    conn.Open()

    cmd.ExecuteNonQuery()




    conn.Close()

    lblStatus.Text = "Backup added to the database!"
End Sub
End Class

我不知道我哪里出错了。

1 个答案:

答案 0 :(得分:0)

tomato是SQL Server中的reserved keyword

尝试Sub CopyPaste() Dim r As Variant Dim a As Variant Dim b As Integer Dim nbcells As Integer Dim ws As Worksheet Worksheets("List").Activate nbcells = Application.WorksheetFunction.CountA(Range("A2:A" & Range("A65536").End(xlUp).Row)) ' === Create a new sheet === For r = 2 To nbcells Sheets.Add After:=Sheets(Sheets.Count - 1) Worksheets(r).Name = Worksheets("List").Cells(r + 1, 1).Value Next r ' === DATA === For Each ws In Sheets If ws.Name Like "*.xls*" Then For a = 2 To nbcells Windows(a).Activate Range("B:B").SpecialCells(2).Copy Workbooks("vegetables_fruits.xlsm").Activate b = a + 1 If ws.Name = Worksheets("List").Cells(b, 1).Value Then ws.Select Range("A2").Select ActiveSheet.Paste End If Next a End If Next End Sub