我尝试 LINQ 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
谢谢你的时间:)