本文介绍了需要帮忙 !!数据未保存在sql server数据库中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
    Dim cnn As New SqlConnection
    Dim cmd As New SqlCommand

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        cmd.Connection = cnn
        cmd = New SqlCommand("insert into info(id, address) values('" & TextBox1.Text & "','" & TextBox2.Text & "')", cnn)
        cmd.ExecuteNonQuery()
        MsgBox("data saved successfully.")

        cnn.Close()

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cnn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\Database1.mdf; Integrated Security=True;User Instance=True"
        cnn.Open()
    End Sub
End Class









我是否需要添加更多数据才能将数据从文本框保存到数据库?





Do I need to add more to save the data from the textboxes to database?

推荐答案


这篇关于需要帮忙 !!数据未保存在sql server数据库中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:49