2013-05-07 24 views
0

這是我OfficeEquipment.Frm調用函數要在運行Windows的形式使用

Public Function Loadfunction() 
dt = Functions.LoadData() 
End Function 

,這是上面的代碼

警告1個功能「Loadfunction」不返回值的誤差在所有代碼路徑上。使用結果時,運行時可能會發生空引用異常。 C:\ Documents and Settings \ IJDinglasan \ My Documents \ Visual Studio 2008 \ Projects \電子辦公設備歷史\電子辦公設備歷史\更新辦公設備Profile.vb 9 5電子辦公設備歷史

這是我的模塊功能

Private Function LoadData() As DataTable 

Using sqlconn = New SqlClient.SqlConnection("server = SKPI-APPS1;" & _ 
              "Database = EOEMS;integrated security=true") 
Dim dt As New DataTable 
sqlconn.Open() 
Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentProfile", sqlconn) 
da.Fill(dt) 
Return dt 
End Using 
End Function 

回答

0

基本上只是使用類,你具備的功能....

Dim dt As DataTable 
dt = yourclass.LoadData() 

現在dt爲你的表,你可以用你喜歡的地方。

MrCoDeXeR

EDITS

你在哪裏都必須你的函數(LoadData),你需要引用類和功能。例如:說我的主要類是:frmMain.vb和我的類有我的功能是:frmStudents我想獲得該功能。

所以....在frmMain.vb您需要申報的其他DataTable中,併爲其分配....見下文......

Dim dt As DataTable 
dt = frmStudents.LoadData() 

我們從frmStudents調用函數,把我們的新表我們的數據。你需要做的是設置一個斷點:dt = frmStudents.LoadData()並運行你的解決方案。當你到達那條線時,按下F-11,看看它是否跳到你的其他職業,你的功能。然後按下F-11並繼續逐步查看是否引發錯誤。在你的:在你的函數中返回dt,將鼠標懸停在此上方,然後單擊放大鏡,查看數據是否存在或是否有列名,如果是這樣,那麼你的好名字就是...

+0

sir yourclass is the class1.vb? – ivandinglasan 2013-05-07 02:17:17

+0

是的,任何類都包含你的功能。 – Codexer 2013-05-07 02:18:21

+0

我把它命名爲它的功能 dim dt as datatable dt = functions.loadData但不起作用 – ivandinglasan 2013-05-07 02:21:16