读书人

在 System.ArgumentException 中第一次

发布时间: 2011-12-18 22:54:38 作者: rapoo

在 System.ArgumentException 中第一次偶然出现的“System.Data.dll”类型的异常
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
SqlConnection myconn=new SqlConnection ( "Server=tingting ;Integrated Security=True;DataBase=northwind ");

myconn.Open();
SqlCommand mycomm = myconn.CreateCommand();
mycomm.CommandText = "select customerid from customers ";
SqlDataReader myreader = mycomm.ExecuteReader();
while (myreader.Read())
{
label1.Text = myreader[ "customerid "].ToString();

}
myreader.Close();
myconn.Close();


}
}
}
如上是代码,出现错误提示在 System.ArgumentException 中第一次偶然出现的“System.Data.dll”类型的异常,但是能运行,不知道是什么意思。就10分可用了,别嫌少啊!

[解决办法]
SqlDataReader myreader = mycomm.ExecuteReader();
这一行如果取数出现错误反回的可能是一个null类型,所以会出现问题。

读书人网 >asp.net

热点推荐