且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

帮助向数据库添加数据

更新时间:2022-11-27 11:38:47

您需要返回从那里获得的信息,然后再获取其余信息.坦白说,这只是一部分代码(我从您的上一个问题中可以识别出其中的一部分),它们看起来并不是为了协同工作而设计的.

例如:
You need to go back to where you got that from, and get the rest of it. Because frankly, that is just partial bits of code (one of which I recognise from a previous question of yours) that don''t look designed to work together.

For example:
Private Sub Sl_NoTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sl_NoTextBox.TextChanged
    Dim dt As New DataTable
    Dim da As New SqlDataAdapter("select max(sl_no) from e1 where project.project_id and e1.project_id = '" + Project_IDTextBox.Text + "'", con)
End Sub

将不执行任何操作. DataAdapter和DataTable仍未连接,并且它们都超出范围,因此在方法结束时未使用. (忽略了您仍在使用字符串连接来构建SQL查询,正如我上次告诉您的那样,这是一种危险的做法)

停止抓住随机的代码块并寄希望于此:这不是一个好的开发策略.考虑您的问题并一步一步地工作会好得多.

Will do nothing. The DataAdapter and the DataTable are still not connected, and they both go out of scope and are thus unused at the end of the method. (Ignoring that you still are using string concatenation to build SQL queries, which as I told you last time is a dangerous practice)

Stop grabbing random lumps of code and hoping: that is not a good development strategy. Thinking about your problem and working in small steps is a much, much better one.


我通过在表格中添加表格活页夹保存按钮来解决了这个问题.

代码是

I solved this myself by adding the table binder save button to the form.

the code is

Private Sub E1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles E1BindingNavigatorSaveItem.Click

        MsgBox(Sl_NoTextBox.Text)
        Me.Validate()
        Me.E1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ProcurementDataSet)

    End Sub




任何方式都感谢您提供的原始信息.




Any ways thanks for the information originalgriff.