Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlConnection = New SqlConnection("Data Source=.\sqlexpress;Initial Catalog=StudentInfoDatabase;Integrated Security=True;Pooling=False")
Dim cmd As SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cmd = New SqlCommand("Insert into StudentInfoTable values('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & ComboBox1.Text & "','" & DateTimePicker1.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & ComboBox2.Text & "','" & TextBox1.Text & "')", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Display()
End Sub
Public Sub Display()
Dim da As SqlDataAdapter
Dim ds As New DataSet
cmd = New SqlCommand("Select * from StudentInfoTable", con)
con.Open()
da = New SqlDataAdapter(cmd)
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
con.Close()
End Sub
No comments:
Post a Comment