資訊系統與資料庫的實踐課作業,做一個售書管理系統,分店員和顧客的,資料庫用的SQL service 2005,前端用的Visual Studio 2008。
我做的先一個登錄界面,然后輸入不同帳號進入不同界面,可無論店員的還是顧客的都閃退,沒有任何報錯,代碼也沒有紅色波浪線,好幾天了都沒弄好,周四就要交報告了,請大神指點。
PS:我不是學計算機的,沒學過VB,資料庫就剛上這一學期,請大神解釋的通俗點……
下面粘代碼了,這是店員的:
Imports System.Data.SqlClient
Public Class Form3
Inherits System.Windows.Forms.Form
Public mybind As BindingManagerBase
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DataSet11.book)
mybind = BindingContext(DataSet11, "book")
DataGrid1.DataSource = DataSet11.book
DataGrid2.DataSource = DataSet11.book
GroupBox2.Visible = False
GroupBox1.Visible = True
GroupBox3.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
GroupBox2.Visible = False
GroupBox1.Visible = True
GroupBox3.Visible = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
GroupBox1.Visible = False
GroupBox2.Visible = True
GroupBox3.Visible = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
mybind.AddNew()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
mybind.RemoveAt(mybind.Position)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
mybind.EndCurrentEdit()
SqlDataAdapter1.Update(DataSet11.book)
End Sub
Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
mybind.Position = DataGrid1.CurrentRowIndex
End Sub
Private Sub DataGrid2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid2.Click
mybind.Position = DataGrid2.CurrentRowIndex
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
mybind.EndCurrentEdit()
SqlDataAdapter1.Update(DataSet11.book)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
GroupBox1.Visible = False
GroupBox2.Visible = False
GroupBox3.Visible = True
End Sub
End Class
界面是這樣的



這個是顧客的
Imports System.Data.SqlClient
Public Class Form4
Inherits System.Windows.Forms.Form
Public mybind As BindingManagerBase
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox1.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
GroupBox1.Visible = False
GroupBox3.Visible = False
GroupBox2.Visible = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
GroupBox1.Visible = False
GroupBox2.Visible = False
GroupBox3.Visible = True
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim sql As String = "select bookname as 書名,price as 價格, publisher as 出版社 from book where bookname ='" & TextBox1.Text & "'"
Dim myconn As New SqlConnection("initial catalog = book;data source=(local);integrated security=sspi;")
Dim myadaper As SqlDataAdapter = New SqlDataAdapter(sql, myconn)
Dim mydataset As New DataSet
myadaper.Fill(mydataset, "book")
DataGrid1.DataSource = mydataset.Tables("book")
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
mybind.EndCurrentEdit()
SqlDataAdapter1.Update(DataSet11.customer)
End Sub
Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlDataAdapter2.Fill(DataSet11.customer)
mybind = BindingContext(DataSet11, "Customer")
SqlDataAdapter1.Fill(DataSet11.BookOrder)
mybind = BindingContext(DataSet11, "BookOrder")
DataGrid1.DataSource = DataSet11.BookOrder
Dim myconn As New SqlConnection("Initial Catalog = Bookxp; Data Source=(Local);Integrated Security=SSPI;")
Dim sql As String = "Select CustomerCode,Name,Sex,Job,Birthday,Hometown,Email,Telephone," _
& "VIPClass From Customer Where Customer.CustomerCode='01010101'"
Dim mycmd As New SqlCommand(sql, myconn)
Dim myread As SqlDataReader
myconn.Open()
myread = mycmd.ExecuteReader
myread.Read()
TextBox10.Text = myread.Item(0)
TextBox2.Text = myread.Item(1)
TextBox3.Text = myread.Item(2)
TextBox4.Text = myread.Item(3)
TextBox5.Text = myread.Item(4)
TextBox6.Text = myread.Item(5)
TextBox7.Text = myread.Item(6)
TextBox8.Text = myread.Item(7)
TextBox9.Text = myread.Item(8)
myread.Close()
myconn.Close()
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox1.Visible = True
End Sub
End Class
界面是這樣的


uj5u.com熱心網友回復:
不知道什么是閃退你把你的斷點設定在執行代碼的第一行,然后手動debug不就知道了
uj5u.com熱心網友回復:
其實就是自動結束除錯了
你這么一說我終于想起如何從中間開始除錯的方法了,只不過明天端午節機房不開門,自己電腦軟體又沒裝……
不過我一直覺得是form load 里的問題,尤其這里
SqlDataAdapter1.Fill(DataSet11.book)
mybind = BindingContext(DataSet11, "book")
DataGrid1.DataSource = DataSet11.book
DataGrid2.DataSource = DataSet11.book
沒覺得哪里有錯……
uj5u.com熱心網友回復:
你的Dataset11連接好了沒有啊uj5u.com熱心網友回復:
應該連接好了,不過我也沒法查看,只能今天下午再去機房檢驗一下了
uj5u.com熱心網友回復:
先在查詢分析器里面手動執行SQL陳述句無誤再說。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/155865.html
標籤:VB基礎類
上一篇:vb6寫入excel報錯
下一篇:VB 多串口通信
