none
帮帮忙,我有个问题? RRS feed

  • 问题

  • 我在设计数据库时,完成后,在使用时没法用程序将数据存入数据库,怎么回事? 我摸索了几天也没摸出来?
    2009年10月24日 7:17

答案

全部回复

  • 你好!
         如果方便的话,可以提供你的源代码吗?
    周雪峰
    2009年10月24日 11:45
    版主
  • 我的被我给删了,等二天,我重新把这个程序发到上面
    2009年10月26日 7:04
  • <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class Form2
        Inherits System.Windows.Forms.Form
    
        'Form 重写 Dispose,以清理组件列表。
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Windows 窗体设计器所必需的
        Private components As System.ComponentModel.IContainer
    
        '注意: 以下过程是 Windows 窗体设计器所必需的
        '可以使用 Windows 窗体设计器修改它。
        '不要使用代码编辑器修改它。
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Dim 编码Label As System.Windows.Forms.Label
            Dim 姓名Label As System.Windows.Forms.Label
            Dim 地址Label As System.Windows.Forms.Label
            Dim 电话号码Label As System.Windows.Forms.Label
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form2))
            Me.Button1 = New System.Windows.Forms.Button
            Me.TB1 = New System.Windows.Forms.TextBox
            Me.TB2 = New System.Windows.Forms.TextBox
            Me.电话号码簿BindingNavigator = New System.Windows.Forms.BindingNavigator(Me.components)
            Me.BindingNavigatorAddNewItem = New System.Windows.Forms.ToolStripButton
            Me.BindingNavigatorCountItem = New System.Windows.Forms.ToolStripLabel
            Me.BindingNavigatorDeleteItem = New System.Windows.Forms.ToolStripButton
            Me.BindingNavigatorMoveFirstItem = New System.Windows.Forms.ToolStripButton
            Me.BindingNavigatorMovePreviousItem = New System.Windows.Forms.ToolStripButton
            Me.BindingNavigatorSeparator = New System.Windows.Forms.ToolStripSeparator
            Me.BindingNavigatorPositionItem = New System.Windows.Forms.ToolStripTextBox
            Me.BindingNavigatorSeparator1 = New System.Windows.Forms.ToolStripSeparator
            Me.BindingNavigatorMoveNextItem = New System.Windows.Forms.ToolStripButton
            Me.BindingNavigatorMoveLastItem = New System.Windows.Forms.ToolStripButton
            Me.BindingNavigatorSeparator2 = New System.Windows.Forms.ToolStripSeparator
            Me.电话号码簿BindingNavigatorSaveItem = New System.Windows.Forms.ToolStripButton
            Me.编码TB = New System.Windows.Forms.TextBox
            Me.姓名TB = New System.Windows.Forms.TextBox
            Me.地址TB = New System.Windows.Forms.TextBox
            Me.电话号码TB = New System.Windows.Forms.TextBox
            Me.Button2 = New System.Windows.Forms.Button
            Me.电话号码簿BindingSource = New System.Windows.Forms.BindingSource(Me.components)
            Me.电话号码簿DataSet = New WindowsApplication1.电话号码簿DataSet
            Me.电话号码簿TableAdapter = New WindowsApplication1.电话号码簿DataSetTableAdapters.电话号码簿TableAdapter
            编码Label = New System.Windows.Forms.Label
            姓名Label = New System.Windows.Forms.Label
            地址Label = New System.Windows.Forms.Label
            电话号码Label = New System.Windows.Forms.Label
            CType(Me.电话号码簿BindingNavigator, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.电话号码簿BindingNavigator.SuspendLayout()
            CType(Me.电话号码簿BindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.电话号码簿DataSet, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            '编码Label
            '
            编码Label.AutoSize = True
            编码Label.Location = New System.Drawing.Point(359, 96)
            编码Label.Name = "编码Label"
            编码Label.Size = New System.Drawing.Size(35, 12)
            编码Label.TabIndex = 4
            编码Label.Text = "编码:"
            '
            '姓名Label
            '
            姓名Label.AutoSize = True
            姓名Label.Location = New System.Drawing.Point(359, 123)
            姓名Label.Name = "姓名Label"
            姓名Label.Size = New System.Drawing.Size(35, 12)
            姓名Label.TabIndex = 6
            姓名Label.Text = "姓名:"
            '
            '地址Label
            '
            地址Label.AutoSize = True
            地址Label.Location = New System.Drawing.Point(359, 150)
            地址Label.Name = "地址Label"
            地址Label.Size = New System.Drawing.Size(35, 12)
            地址Label.TabIndex = 8
            地址Label.Text = "地址:"
            '
            '电话号码Label
            '
            电话号码Label.AutoSize = True
            电话号码Label.Location = New System.Drawing.Point(359, 177)
            电话号码Label.Name = "电话号码Label"
            电话号码Label.Size = New System.Drawing.Size(59, 12)
            电话号码Label.TabIndex = 10
            电话号码Label.Text = "电话号码:"
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(36, 238)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(172, 61)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "计算"
            Me.Button1.UseVisualStyleBackColor = True
            '
            'TB1
            '
            Me.TB1.Location = New System.Drawing.Point(50, 96)
            Me.TB1.Name = "TB1"
            Me.TB1.Size = New System.Drawing.Size(92, 21)
            Me.TB1.TabIndex = 1
            '
            'TB2
            '
            Me.TB2.Location = New System.Drawing.Point(50, 149)
            Me.TB2.Name = "TB2"
            Me.TB2.Size = New System.Drawing.Size(92, 21)
            Me.TB2.TabIndex = 2
            '
            '电话号码簿BindingNavigator
            '
            Me.电话号码簿BindingNavigator.AddNewItem = Me.BindingNavigatorAddNewItem
            Me.电话号码簿BindingNavigator.BindingSource = Me.电话号码簿BindingSource
            Me.电话号码簿BindingNavigator.CountItem = Me.BindingNavigatorCountItem
            Me.电话号码簿BindingNavigator.DeleteItem = Me.BindingNavigatorDeleteItem
            Me.电话号码簿BindingNavigator.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.BindingNavigatorMoveFirstItem, Me.BindingNavigatorMovePreviousItem, Me.BindingNavigatorSeparator, Me.BindingNavigatorPositionItem, Me.BindingNavigatorCountItem, Me.BindingNavigatorSeparator1, Me.BindingNavigatorMoveNextItem, Me.BindingNavigatorMoveLastItem, Me.BindingNavigatorSeparator2, Me.BindingNavigatorAddNewItem, Me.BindingNavigatorDeleteItem, Me.电话号码簿BindingNavigatorSaveItem})
            Me.电话号码簿BindingNavigator.Location = New System.Drawing.Point(0, 0)
            Me.电话号码簿BindingNavigator.MoveFirstItem = Me.BindingNavigatorMoveFirstItem
            Me.电话号码簿BindingNavigator.MoveLastItem = Me.BindingNavigatorMoveLastItem
            Me.电话号码簿BindingNavigator.MoveNextItem = Me.BindingNavigatorMoveNextItem
            Me.电话号码簿BindingNavigator.MovePreviousItem = Me.BindingNavigatorMovePreviousItem
            Me.电话号码簿BindingNavigator.Name = "电话号码簿BindingNavigator"
            Me.电话号码簿BindingNavigator.PositionItem = Me.BindingNavigatorPositionItem
            Me.电话号码簿BindingNavigator.Size = New System.Drawing.Size(715, 25)
            Me.电话号码簿BindingNavigator.TabIndex = 3
            Me.电话号码簿BindingNavigator.Text = "BindingNavigator1"
            '
            'BindingNavigatorAddNewItem
            '
            Me.BindingNavigatorAddNewItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.BindingNavigatorAddNewItem.Image = CType(resources.GetObject("BindingNavigatorAddNewItem.Image"), System.Drawing.Image)
            Me.BindingNavigatorAddNewItem.Name = "BindingNavigatorAddNewItem"
            Me.BindingNavigatorAddNewItem.RightToLeftAutoMirrorImage = True
            Me.BindingNavigatorAddNewItem.Size = New System.Drawing.Size(23, 22)
            Me.BindingNavigatorAddNewItem.Text = "新添"
            '
            'BindingNavigatorCountItem
            '
            Me.BindingNavigatorCountItem.Name = "BindingNavigatorCountItem"
            Me.BindingNavigatorCountItem.Size = New System.Drawing.Size(30, 22)
            Me.BindingNavigatorCountItem.Text = "/ {0}"
            Me.BindingNavigatorCountItem.ToolTipText = "总项数"
            '
            'BindingNavigatorDeleteItem
            '
            Me.BindingNavigatorDeleteItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.BindingNavigatorDeleteItem.Image = CType(resources.GetObject("BindingNavigatorDeleteItem.Image"), System.Drawing.Image)
            Me.BindingNavigatorDeleteItem.Name = "BindingNavigatorDeleteItem"
            Me.BindingNavigatorDeleteItem.RightToLeftAutoMirrorImage = True
            Me.BindingNavigatorDeleteItem.Size = New System.Drawing.Size(23, 22)
            Me.BindingNavigatorDeleteItem.Text = "删除"
            '
            'BindingNavigatorMoveFirstItem
            '
            Me.BindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.BindingNavigatorMoveFirstItem.Image = CType(resources.GetObject("BindingNavigatorMoveFirstItem.Image"), System.Drawing.Image)
            Me.BindingNavigatorMoveFirstItem.Name = "BindingNavigatorMoveFirstItem"
            Me.BindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = True
            Me.BindingNavigatorMoveFirstItem.Size = New System.Drawing.Size(23, 22)
            Me.BindingNavigatorMoveFirstItem.Text = "移到第一条记录"
            '
            'BindingNavigatorMovePreviousItem
            '
            Me.BindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.BindingNavigatorMovePreviousItem.Image = CType(resources.GetObject("BindingNavigatorMovePreviousItem.Image"), System.Drawing.Image)
            Me.BindingNavigatorMovePreviousItem.Name = "BindingNavigatorMovePreviousItem"
            Me.BindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = True
            Me.BindingNavigatorMovePreviousItem.Size = New System.Drawing.Size(23, 22)
            Me.BindingNavigatorMovePreviousItem.Text = "移到上一条记录"
            '
            'BindingNavigatorSeparator
            '
            Me.BindingNavigatorSeparator.Name = "BindingNavigatorSeparator"
            Me.BindingNavigatorSeparator.Size = New System.Drawing.Size(6, 25)
            '
            'BindingNavigatorPositionItem
            '
            Me.BindingNavigatorPositionItem.AccessibleName = "位置"
            Me.BindingNavigatorPositionItem.AutoSize = False
            Me.BindingNavigatorPositionItem.Name = "BindingNavigatorPositionItem"
            Me.BindingNavigatorPositionItem.Size = New System.Drawing.Size(50, 21)
            Me.BindingNavigatorPositionItem.Text = "0"
            Me.BindingNavigatorPositionItem.ToolTipText = "当前位置"
            '
            'BindingNavigatorSeparator1
            '
            Me.BindingNavigatorSeparator1.Name = "BindingNavigatorSeparator1"
            Me.BindingNavigatorSeparator1.Size = New System.Drawing.Size(6, 25)
            '
            'BindingNavigatorMoveNextItem
            '
            Me.BindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.BindingNavigatorMoveNextItem.Image = CType(resources.GetObject("BindingNavigatorMoveNextItem.Image"), System.Drawing.Image)
            Me.BindingNavigatorMoveNextItem.Name = "BindingNavigatorMoveNextItem"
            Me.BindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = True
            Me.BindingNavigatorMoveNextItem.Size = New System.Drawing.Size(23, 22)
            Me.BindingNavigatorMoveNextItem.Text = "移到下一条记录"
            '
            'BindingNavigatorMoveLastItem
            '
            Me.BindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.BindingNavigatorMoveLastItem.Image = CType(resources.GetObject("BindingNavigatorMoveLastItem.Image"), System.Drawing.Image)
            Me.BindingNavigatorMoveLastItem.Name = "BindingNavigatorMoveLastItem"
            Me.BindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = True
            Me.BindingNavigatorMoveLastItem.Size = New System.Drawing.Size(23, 22)
            Me.BindingNavigatorMoveLastItem.Text = "移到最后一条记录"
            '
            'BindingNavigatorSeparator2
            '
            Me.BindingNavigatorSeparator2.Name = "BindingNavigatorSeparator2"
            Me.BindingNavigatorSeparator2.Size = New System.Drawing.Size(6, 25)
            '
            '电话号码簿BindingNavigatorSaveItem
            '
            Me.电话号码簿BindingNavigatorSaveItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
            Me.电话号码簿BindingNavigatorSaveItem.Image = CType(resources.GetObject("电话号码簿BindingNavigatorSaveItem.Image"), System.Drawing.Image)
            Me.电话号码簿BindingNavigatorSaveItem.Name = "电话号码簿BindingNavigatorSaveItem"
            Me.电话号码簿BindingNavigatorSaveItem.Size = New System.Drawing.Size(23, 22)
            Me.电话号码簿BindingNavigatorSaveItem.Text = "保存数据"
            '
            '编码TB
            '
            Me.编码TB.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.电话号码簿BindingSource, "编码", True))
            Me.编码TB.Location = New System.Drawing.Point(424, 93)
            Me.编码TB.Name = "编码TB"
            Me.编码TB.Size = New System.Drawing.Size(100, 21)
            Me.编码TB.TabIndex = 5
            '
            '姓名TB
            '
            Me.姓名TB.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.电话号码簿BindingSource, "姓名", True))
            Me.姓名TB.Location = New System.Drawing.Point(424, 120)
            Me.姓名TB.Name = "姓名TB"
            Me.姓名TB.Size = New System.Drawing.Size(100, 21)
            Me.姓名TB.TabIndex = 7
            '
            '地址TB
            '
            Me.地址TB.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.电话号码簿BindingSource, "地址", True))
            Me.地址TB.Location = New System.Drawing.Point(424, 147)
            Me.地址TB.Name = "地址TB"
            Me.地址TB.Size = New System.Drawing.Size(100, 21)
            Me.地址TB.TabIndex = 9
            '
            '电话号码TB
            '
            Me.电话号码TB.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.电话号码簿BindingSource, "电话号码", True))
            Me.电话号码TB.Location = New System.Drawing.Point(424, 174)
            Me.电话号码TB.Name = "电话号码TB"
            Me.电话号码TB.Size = New System.Drawing.Size(100, 21)
            Me.电话号码TB.TabIndex = 11
            '
            'Button2
            '
            Me.Button2.Location = New System.Drawing.Point(428, 287)
            Me.Button2.Name = "Button2"
            Me.Button2.Size = New System.Drawing.Size(129, 37)
            Me.Button2.TabIndex = 12
            Me.Button2.Text = "创建数据库"
            Me.Button2.UseVisualStyleBackColor = True
            '
            '电话号码簿BindingSource
            '
            Me.电话号码簿BindingSource.DataMember = "电话号码簿"
            Me.电话号码簿BindingSource.DataSource = Me.电话号码簿DataSet
            '
            '电话号码簿DataSet
            '
            Me.电话号码簿DataSet.DataSetName = "电话号码簿DataSet"
            Me.电话号码簿DataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
            '
            '电话号码簿TableAdapter
            '
            Me.电话号码簿TableAdapter.ClearBeforeFill = True
            '
            'Form2
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(715, 443)
            Me.Controls.Add(Me.Button2)
            Me.Controls.Add(编码Label)
            Me.Controls.Add(Me.编码TB)
            Me.Controls.Add(姓名Label)
            Me.Controls.Add(Me.姓名TB)
            Me.Controls.Add(地址Label)
            Me.Controls.Add(Me.地址TB)
            Me.Controls.Add(电话号码Label)
            Me.Controls.Add(Me.电话号码TB)
            Me.Controls.Add(Me.电话号码簿BindingNavigator)
            Me.Controls.Add(Me.TB2)
            Me.Controls.Add(Me.TB1)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form2"
            Me.Text = "Form2"
            CType(Me.电话号码簿BindingNavigator, System.ComponentModel.ISupportInitialize).EndInit()
            Me.电话号码簿BindingNavigator.ResumeLayout(False)
            Me.电话号码簿BindingNavigator.PerformLayout()
            CType(Me.电话号码簿BindingSource, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.电话号码簿DataSet, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()
    
        End Sub
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents TB1 As System.Windows.Forms.TextBox
        Friend WithEvents TB2 As System.Windows.Forms.TextBox
        Friend WithEvents 电话号码簿DataSet As WindowsApplication1.电话号码簿DataSet
        Friend WithEvents 电话号码簿BindingSource As System.Windows.Forms.BindingSource
        Friend WithEvents 电话号码簿TableAdapter As WindowsApplication1.电话号码簿DataSetTableAdapters.电话号码簿TableAdapter
        Friend WithEvents 电话号码簿BindingNavigator As System.Windows.Forms.BindingNavigator
        Friend WithEvents BindingNavigatorAddNewItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents BindingNavigatorCountItem As System.Windows.Forms.ToolStripLabel
        Friend WithEvents BindingNavigatorDeleteItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents BindingNavigatorMoveFirstItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents BindingNavigatorMovePreviousItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents BindingNavigatorSeparator As System.Windows.Forms.ToolStripSeparator
        Friend WithEvents BindingNavigatorPositionItem As System.Windows.Forms.ToolStripTextBox
        Friend WithEvents BindingNavigatorSeparator1 As System.Windows.Forms.ToolStripSeparator
        Friend WithEvents BindingNavigatorMoveNextItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents BindingNavigatorMoveLastItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents BindingNavigatorSeparator2 As System.Windows.Forms.ToolStripSeparator
        Friend WithEvents 电话号码簿BindingNavigatorSaveItem As System.Windows.Forms.ToolStripButton
        Friend WithEvents 编码TB As System.Windows.Forms.TextBox
        Friend WithEvents 姓名TB As System.Windows.Forms.TextBox
        Friend WithEvents 地址TB As System.Windows.Forms.TextBox
        Friend WithEvents 电话号码TB As System.Windows.Forms.TextBox
        Friend WithEvents Button2 As System.Windows.Forms.Button
    End Class
    
    
    
    Public Class Form2
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim x As Integer, y As Integer, z As Integer
            x = TB1.Text
            y = TB2.Text
            z = x + y
            TB2.Text = z
        End Sub
    
        Private Sub 电话号码簿BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 电话号码簿BindingNavigatorSaveItem.Click
            Me.Validate()
            Me.电话号码簿BindingSource.EndEdit()
            Me.电话号码簿TableAdapter.Update(Me.电话号码簿DataSet.电话号码簿)
    
        End Sub
    
        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: 这行代码将数据加载到表“电话号码簿DataSet.电话号码簿”中。您可以根据需要移动或移除它。
            Me.电话号码簿TableAdapter.Fill(Me.电话号码簿DataSet.电话号码簿)
    
        End Sub
    
        Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
            Dim sqlcmd As New System.Data.SqlClient.SqlCommand
            sqlcmd.CommandText = "INSERT  INTO    电话号码簿  电话号码簿()  VALUES(编码TB.text,姓名TB.text,地址TB.text,电话号码TB.text )"
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.CommandText = "CREATE DATABASE ligong "
    
        End Sub
    
        Private Sub 电话号码簿BindingNavigator_RefreshItems(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 电话号码簿BindingNavigator.RefreshItems
    
        End Sub
    End Class
    你好,这是我的程序源码,请帮我看看,怎么回事,先谢了!
    2009年10月27日 2:41
  • 这些是自动生成的代码,应该没有问题的!

    周雪峰
    2009年10月27日 8:09
    版主
  • 可就是不能储存数据,点过之后没反应,到数据库中一看,还是空的,怎么回事?

    2009年10月27日 23:58
  • 很可能是连接字符指定的数据库位置为相对位置,每次调试时使用的是调试数据库
    2009年10月30日 12:36
  • 谢谢,我再试试看.
    2009年10月31日 1:49
  • 边连边试试看哪里出错?

    2009年10月31日 13:54
  • 你查找依稀是不是有多个相同的数据库名,修改和查看的不是同一个
    http://feiyun0112.cnblogs.com/
    • 已标记为答案 李公顺 2012年7月15日 10:04
    2009年11月2日 1:28
    版主