这个c#程序错在哪里

来源:百度知道 编辑:UC知道 时间:2024/06/08 07:04:06
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 shiyan9
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string connectionString = Properties.Settings.Default.MyDatabaseConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("select [学号],[姓名] from MyTable2", conn);
try
{
conn.Open();
SqlDataReader r = cmd.ExecuteReader();
while (r.Read() == true)
{

listBox1.Items.Add(string.Format("[{0}]{1}", r[0], r[1]));

感觉这一点有错误

测试一下你把问题贴出来


这么长懒的看了,自己运行的时候,下面有显示。
自己去看看吧。
报错很正常,自己去找吧。

错误信息呢?