我正在使用 vb.net
我的类(class1)文件中有一个函数,即保存。这个 Save 函数有 3 个参数。现在我使用以下方法来发送参数。
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
dim p as new class1
p.save(txtempid.text,txtempname.text,txtage.text)
messagebox.show("Successfully Saved")
End sub
第一类:
imports system.data.sqlclient
imports system.configuration
public class class1
Dim constr As String
Dim con As SqlConnection
Dim cmd As SqlCommand
public function save(byval s as string,byval s1 as string,byval s2 as string)
constr = ConfigurationManager.AppSettings("con")
con = New SqlConnection(constr)
con.Open()
cmd=new sqlcommand("Emp_insert",con)
cmd.commandtype=commandtype.storedprocedure
cmd.Parameters.Add("@EmployeeID", SqlDbType.BigInt).Value = s
cmd.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = s1
cmd.Parameters.Add("@Age", SqlDbType.BigInt).Value = s2
cmd.executenonquery()
cmd.dispose()
con.close()
return 0
End function
End Class
没关系,但是当我有更多的论点时,这很难。有人可以建议我更好的方法吗?