
Шустрый

Профиль
Группа: Участник
Сообщений: 54
Регистрация: 3.12.2007
Репутация: 1 Всего: 1
|
| Код | Imports System Imports System.Collections Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Diagnostics Imports System.Drawing Imports System.Drawing.Design Imports System.Data Imports System.Text Imports System.Windows.Forms Imports System.Windows.Forms.Design Imports System.Data.Sql Imports System.Data.SqlClient
Public Class Stuff Private dsUchen As New DataSet Private connection As New SqlConnection("Initial catalog =School;Trusted_connection = Yes") Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cmd As New SqlCommand("Select*from School_Stuff", connection) Dim adapter As New SqlDataAdapter(cmd) Dim ds As DataSet = dsUchen adapter.Fill(ds, "School_Stuff") DataGridView1.DataSource = ds.Tables("School_Stuff").DefaultView End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ds As DataSet = dsUchen Dim adapter As New SqlDataAdapter() If ds.HasChanges Then 'Dim connection As New SqlConnection("Initial catalog =School;Trusted_connection = Yes") Try connection.Open() Dim numer As SqlParameter Dim dir As SqlParameter Dim zav As SqlParameter Dim bibl As SqlParameter Dim uchi As SqlParameter Dim stor As SqlParameter Dim ubor As SqlParameter Dim povor As SqlParameter
'Insert COmmand '_____________________________________________ Dim cmd As New SqlCommand("Insert into School_Stuff values(@number,@dir,@zav,@bibl,@uchit,@stor,@ubor,@povor)", connection) 'Команда на выполнение numer = cmd.Parameters.Add("@number", SqlDbType.Int, 15, "Number") dir = cmd.Parameters.Add("@dir", SqlDbType.Int, 14, "direktor") zav = cmd.Parameters.Add("@zav", SqlDbType.Int, 15, "zavuch") bibl = cmd.Parameters.Add("@bibl", SqlDbType.Int, 15, "Bibliotekar") uchi = cmd.Parameters.Add("@uchit", SqlDbType.Int, 14, "uchtelya") stor = cmd.Parameters.Add("@stor", SqlDbType.Int, 14, "Storoj") ubor = cmd.Parameters.Add("@ubor", SqlDbType.Int, 15, "Uborshica") povor = cmd.Parameters.Add("@povor", SqlDbType.Int, 15, "povara") numer.SourceVersion = DataRowVersion.Current dir.SourceVersion = DataRowVersion.Current zav.SourceVersion = DataRowVersion.Current bibl.SourceVersion = DataRowVersion.Current uchi.SourceVersion = DataRowVersion.Current stor.SourceVersion = DataRowVersion.Current ubor.SourceVersion = DataRowVersion.Current povor.SourceVersion = DataRowVersion.Current adapter.InsertCommand = cmd adapter.Update(ds, "School_Stuff") ' Обновление БД Catch ex As Exception MessageBox.Show(ex.ToString) End Try End If End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim ds As DataSet = dsUchen Dim adapter As New SqlDataAdapter()
'Dim connection As New SqlConnection("Initial catalog =School;Trusted_connection = Yes") Try connection.Open() Dim numer As SqlParameter Dim dir As SqlParameter Dim zav As SqlParameter Dim bibl As SqlParameter Dim uchi As SqlParameter Dim stor As SqlParameter Dim ubor As SqlParameter Dim povor As SqlParameter
'Insert COmmand '_____________________________________________ Dim cmd As New SqlCommand("Update School_Stuff set number = @number,direktor=@dir,zavuch=@zav,bibliotekar = @bibl,Uchitelya=@ucht,Storoj=@stor,Uborshica=@ubor,Povara=@povor", connection) 'Команда на выполнение numer = cmd.Parameters.Add("@number", SqlDbType.Int, 15, "Number") dir = cmd.Parameters.Add("@dir", SqlDbType.Int, 14, "direktor") zav = cmd.Parameters.Add("@zav", SqlDbType.Int, 15, "zavuch") bibl = cmd.Parameters.Add("@bibl", SqlDbType.Int, 15, "Bibliotekar") uchi = cmd.Parameters.Add("@uchit", SqlDbType.Int, 14, "uchtelya") stor = cmd.Parameters.Add("@stor", SqlDbType.Int, 14, "Storoj") ubor = cmd.Parameters.Add("@ubor", SqlDbType.Int, 15, "Uborshica") povor = cmd.Parameters.Add("@povor", SqlDbType.Int, 15, "povara") numer.SourceVersion = DataRowVersion.Current dir.SourceVersion = DataRowVersion.Current zav.SourceVersion = DataRowVersion.Current bibl.SourceVersion = DataRowVersion.Current uchi.SourceVersion = DataRowVersion.Current stor.SourceVersion = DataRowVersion.Current ubor.SourceVersion = DataRowVersion.Current povor.SourceVersion = DataRowVersion.Current adapter.UpdateCommand = cmd adapter.Update(ds, "School_Stuff") ' Обновление БД Catch ex As Exception MessageBox.Show(ex.ToString) End Try
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim adapter As New SqlDataAdapter() Dim ds As DataSet = dsUchen Dim delParam As SqlParameter Dim cmdD As New SqlCommand() cmdD.CommandText = "delete from School_Stuff where Tab_Number = @number" delParam = cmdD.Parameters.Add("@number", SqlDbType.Int, 15, "Tab_number") delParam.SourceVersion = DataRowVersion.Current cmdD.Connection = connection adapter.DeleteCommand = cmdD adapter.Update(ds, "School_Stuff") End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim view As New viewtbl view.Show() End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.Hide() End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Application.Exit() End Sub
Private Sub Stuff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cmd As New SqlCommand("Select*from School_Stuff", connection) Dim adapter As New SqlDataAdapter(cmd) Dim ds As DataSet = dsUchen adapter.Fill(ds, "School_Stuff") DataGridView1.DataSource = ds.Tables("School_Stuff").DefaultView End Sub End Class
|
|