本文介绍了如何使用从一种形式到另一种形式的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用vb.net2005.我需要如何使用从一种形式到另一种形式的编码.我还有另外两个表单,例如登录"表单,注册"表单,计算"表单.
我对每种表格使用了相同的代码.但是我需要我仅以一种形式编写通用代码,而在不编写每种形式的情况下习惯于另一种形式.

例如.

Hi,

I am using vb.net 2005. I need, how to use the coding from one form to another form. I have two more forms like, Login form, Registration form, Calculation form.
I used the same code to each forms. But i need i wrote the common code only in one form and it used to another forms without wrote the each forms.

for ex.


Imports System.Data
Imports System.Data.OleDb

Public Class Form1
Dim con As OleDbConnection
Dim com As OleDbCommand
Dim adp As OleDbDataAdapter
Dim reader As OleDbDataReader
Dim ds As DataSet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
.
.
.
.

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\gopi\password\pass.mdb")
con.Open()

End Sub
End Class


上面的粗体代码将以另一种形式使用.我需要使用它而无需写入另一种形式.是否有可能?如果可能,请举例说明.

谢谢
Gopi A


The above bold code will be use in another form. I need to use it without write into another form. Is it possible? if possible means please explain with example.

Thanks
Gopi A

推荐答案


class DBOperations{

// initialize the objects required for database operation here
// you can make use of these objects throughout the class

CreateRecord(){
// Insert operations
}

UpdateRecords(){
// update operations
}

ReadRecords(){
// select operations
}
DeleteRecords(){
// delete operations
}
}



现在,在用户界面中,您要做的就是从此类中调用适当的方法.这堂课会好好休息的.

在这里,我没有提到方法的返回类型,参数和访问修饰符.您可以根据自己的项目来决定.

另外,不要使用硬编码的字符串,而使用配置文件并从那里读取它们.

*我不太了解VB,因此我使用了C#.希望您能理解.



Now, in your UI, all you should do is call the appropriate method from this class. This class will take care of rest.

Here I have not mentioned return types, parameters and access modifiers for the methods. You can decide those depending on your project.

Also, instead of having hardcoded strings, use config files and read them from there.

*I don''t know much of VB hence I used C#. I hope you understand it.



这篇关于如何使用从一种形式到另一种形式的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 11:12