Кнопки Vb следующий предыдущий
Привет,
Может ли кто-нибудь помочь мне, как создать здесь кнопки
- Button7 - Первый
- Button5 - Следующий
- Button6 - Предыдущий
- Button8 - Последний
Для поиска в базе данных и отображения результатов.
Вот мой проект до сих пор:
- Кроме того, если есть ошибки или предложения, чтобы сделать его лучше, я тоже открыт для идей, чтобы учиться :)
Public Class Form2 Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load Using con As New OleDbConnection(ServerStatus) Using cmd As New OleDbCommand("SELECT * FROM Table", con) cmd.CommandType = CommandType.Text Using sda As New OleDbDataAdapter(cmd) Using dt As New DataTable() sda.Fill(dt) 'Set AutoGenerateColumns False DataDisplay.AutoGenerateColumns = False 'DataDisplay.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill DataDisplay.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells DataDisplay.AutoResizeColumns() 'Set Columns Count DataDisplay.ColumnCount = 6 'Add Columns DataDisplay.Columns(0).Name = "ID" DataDisplay.Columns(0).HeaderText = "ID" DataDisplay.Columns(0).DataPropertyName = "ID" DataDisplay.Columns(1).Name = "cName" DataDisplay.Columns(1).HeaderText = "Name" DataDisplay.Columns(1).DataPropertyName = "cName" DataDisplay.Columns(2).Name = "cNumber" DataDisplay.Columns(2).HeaderText = "Number" DataDisplay.Columns(2).DataPropertyName = "cNumber" DataDisplay.Columns(3).Name = "cSupplier" DataDisplay.Columns(3).HeaderText = "Supplier" DataDisplay.Columns(3).DataPropertyName = "cSupplier" DataDisplay.Columns(4).Name = "cStore" DataDisplay.Columns(4).HeaderText = "Store" DataDisplay.Columns(4).DataPropertyName = "cStore" DataDisplay.Columns(5).Name = "cCount" DataDisplay.Columns(5).HeaderText = "Count" DataDisplay.Columns(5).DataPropertyName = "cCount" TextBox1.Text = dt.Rows(0).Item(1) TextBox2.Text = dt.Rows(0).Item(2) TextBox3.Text = dt.Rows(0).Item(3) TextBox4.Text = dt.Rows(0).Item(4) TextBox5.Text = dt.Rows(0).Item(5) TextBox6.Text = dt.Rows(0).Item(0) DataDisplay.DataSource = dt End Using End Using End Using End Using Try With cmd Dim stream As New IO.MemoryStream() conn.Open() .Connection = conn .CommandText = "select cPicture from Table where ID=@uID" .Parameters.Add("@uID", OleDbType.Integer, 50).Value = TextBox6.Text Dim image As Byte() = DirectCast(cmd.ExecuteScalar(), Byte()) stream.Write(image, 0, image.Length) Dim bitmap As New Bitmap(stream) PictureBox1.Image = bitmap '--->I have used another picturebox to display image from database. stream.Close() .Parameters.Clear() End With Catch ex As Exception MsgBox(ex.Message) Finally cmd.Dispose() If conn IsNot Nothing Then conn.Close() End If End Try End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Adapter.Update(dt) Try With cmd Dim stream As New IO.MemoryStream() conn.Open() .Connection = conn .CommandText = "select cPicture from Table where ID=@uID" .Parameters.Add("@uID", OleDbType.Integer, 50).Value = TextBox6.Text Dim image As Byte() = DirectCast(cmd.ExecuteScalar(), Byte()) stream.Write(image, 0, image.Length) Dim bitmap As New Bitmap(stream) PictureBox1.Image = bitmap '--->I have used another picturebox to display image from database. stream.Close() .Parameters.Clear() End With Catch ex As Exception MsgBox(ex.Message) Finally cmd.Dispose() If conn IsNot Nothing Then conn.Close() End If End Try End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim dialog As New OpenFileDialog() dialog.Title = "Browse Picture" dialog.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG" If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then PictureBox1.Image = Image.FromFile(dialog.FileName) 'TextBox1.Text = dialog.FileName.ToString End If End Sub Private Sub RefreshData() Using con As New OleDbConnection(ServerStatus) Using cmd As New OleDbCommand("SELECT * FROM Table", con) cmd.CommandType = CommandType.Text Using sda As New OleDbDataAdapter(cmd) Using dt As New DataTable() sda.Fill(dt) TextBox1.Text = dt.Rows(0).Item(1) TextBox2.Text = dt.Rows(0).Item(2) TextBox3.Text = dt.Rows(0).Item(3) TextBox4.Text = dt.Rows(0).Item(4) TextBox5.Text = dt.Rows(0).Item(5) TextBox6.Text = dt.Rows(0).Item(0) DataDisplay.DataSource = dt End Using End Using End Using End Using Try With cmd Dim stream As New IO.MemoryStream() conn.Open() .Connection = conn .CommandText = "select cPicture from Table where ID=@uID" .Parameters.Add("@uID", OleDbType.Integer, 50).Value = TextBox6.Text Dim image As Byte() = DirectCast(cmd.ExecuteScalar(), Byte()) stream.Write(image, 0, image.Length) Dim bitmap As New Bitmap(stream) PictureBox1.Image = bitmap '--->I have used another picturebox to display image from database. stream.Close() .Parameters.Clear() End With Catch ex As Exception MsgBox(ex.Message) Finally cmd.Dispose() If conn IsNot Nothing Then conn.Close() End If End Try End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Try With cmd Dim ms As New IO.MemoryStream() PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat) Dim arrimage() As Byte = ms.GetBuffer conn.Open() .Connection = conn .Parameters.Add("@uName", OleDbType.VarChar, 50).Value = TextBox1.Text .Parameters.Add("@uNumber", OleDbType.Integer, 50).Value = TextBox2.Text .Parameters.Add("@uSupp", OleDbType.VarChar, 50).Value = TextBox3.Text .Parameters.Add("@uStore", OleDbType.VarChar, 50).Value = TextBox4.Text .Parameters.Add("@uCount", OleDbType.Integer, 50).Value = TextBox5.Text .Parameters.Add("@Picture", OleDbType.Binary).Value = arrimage .Parameters.AddWithValue("@uID", TextBox6.Text) .CommandText = "UPDATE Table SET cName = @uName,cNumber = @uNumber,cSupplier = @uSupp,cStore = @uStore,cCount = @uCount,cPicture = @Picture WHERE ID = @uID" .ExecuteNonQuery() .Parameters.Clear() ms.Close() End With Catch ex As Exception MsgBox(ex.Message) Finally cmd.Dispose() If conn IsNot Nothing Then conn.Close() End If RefreshData() End Try End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click Try With cmd Dim ms As New IO.MemoryStream() PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat) Dim arrimage() As Byte = ms.GetBuffer conn.Open() .Connection = conn .CommandText = "INSERT INTO Table (cName,cNumber,cSupplier,cStore,cCount,cPicture) VALUES (@uName,@uYazaki,@uSupp,@uStore,@uCount,@picture)" .Parameters.Add("@uName", OleDbType.VarChar, 50).Value = TextBox1.Text .Parameters.Add("@uNumber", OleDbType.Integer, 50).Value = TextBox2.Text .Parameters.Add("@uSupp", OleDbType.VarChar, 50).Value = TextBox3.Text .Parameters.Add("@uStore", OleDbType.VarChar, 50).Value = TextBox4.Text .Parameters.Add("@uCount", OleDbType.Integer, 50).Value = TextBox5.Text .Parameters.Add("@Picture", OleDbType.Binary).Value = arrimage .ExecuteNonQuery() .Parameters.Clear() ms.Close() End With Catch ex As Exception MsgBox(ex.Message) Finally cmd.Dispose() If conn IsNot Nothing Then conn.Close() End If End Try End Sub End Class
Что я уже пробовал:
я стараюсь с гидом с
Private Sub ShowData(ByVal CurrentRow) Try Id.Text = Dst.Tables("empinfo").Rows(CurrentRow)("Id") FName.Text = Dst.Tables("empinfo").Rows(CurrentRow)("FName") LName.Text = Dst.Tables("empinfo").Rows(CurrentRow)("LName") Designation.Text = Dst.Tables("empinfo").Rows(CurrentRow)("Designation") Salary.Text = Dst.Tables("empinfo").Rows(CurrentRow)("Salary") Catch ex As Exception MsgBox(ex.Message, "error") End Try End Sub
Как, например, но не сумел сделать это правильно.
Richard MacCutchan
Вы можете начать с использования разумных осмысленных имен для ваших кнопок, таких как "ButtonFirst", "ButtonNext" и т. д. Не используйте только имена по умолчанию, предоставляемые Visual Studio, тем более что ваши имена логически не соответствуют порядку.
diablo22
я могу исправить это на более позднем этапе, currectly im interested on the function to do it