2016-05-12 62 views
-2

我目前正在開發一個使用C#windows應用程序的在線考試系統。填充中的ArgumentException - 期望的非空字符串

當我運行這段代碼我得到以下ArgumentException

填充:預計非空字符串參數SRC表

private void Window1_Loaded(object sender, RoutedEventArgs e) 
{ 
    con.Open(); 
    string testTable = StudentPage.testTable; 
    adp = new SqlDataAdapter("SELECT TOP 5 * FROM " + testTable + " ORDER BY NEWID()", con); 
    ds.Clear(); 
    adp.Fill(ds, testTable); 
    alltables = ds.Tables; 
    MyTable = alltables[testTable]; 
    AllRows = MyTable.Rows; 

    MyRow = AllRows[0]; 
    GetData(); 
    rowPointer = 0; 
    currentPage = 0; 
    crtAnswer = 0; 
    ViewStatus = new bool[] { true, false, false, false, false }; 
    isBookmarked = new bool[] { false, false, false, false, false }; 
    SelectedOption = new int[] { -1, -1, -1, -1, -1 }; 
    MyTimer.Interval = System.TimeSpan.FromSeconds(1); 
    MyTimer.Start(); 
    btnFirst.IsEnabled = false; 
    btnPrevious.IsEnabled = false; 
    lblQuesInfo.Content = "Question 1/5"; 

    WindowState = WindowState.Maximized; 
} 
+1

閱讀異常消息。 'StudentPage.testTable'是一個空字符串。 – CodeCaster

回答

0

你不能爲空字符串傳遞給Fill ,錯誤消息告訴它。

你可以避開它以這樣的方式

if(String.IsNullOrEmppty(testTable)) 
    adp.Fill(ds); 
else 
    adp.Fill(ds, testTable);