我嘗試LINQ VB.NET但它的工作不插入到數據庫VB.NET - 我不插入到數據庫
此行「.CommandText = sqlAdd」
消息錯誤對象引用未設置爲對象的實例。
Imports System
Imports System.Configuration
Imports System.Globalization
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Public Class _1_1Invoice
Dim db As New assetDataContext()
Dim Conn As SqlConnection
Dim cmd As SqlCommand
Dim tr As SqlTransaction
Dim sb As New StringBuilder()
Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
If MessageBox.Show("Do you want insert invoice?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
tr = Conn.BeginTransaction()
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO tbl_AsInvoice (Poid)")
sb.Append(" VALUES (@Poid)")
Dim sqlAdd As String = sb.ToString()
With cmd
.CommandText = sqlAdd
.CommandType = CommandType.Text
.Connection = Conn
.Transaction = tr
.Parameters.Clear()
.Parameters.Add("@Poid", SqlDbType.VarChar).Value = txtPoid.Text.Trim()
.ExecuteNonQuery()
End With
tr.Commit()
MessageBox.Show("Succesfull", "Done", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
感謝您的時間:)
linq在哪裏? –