为什么MessageBox显示NULL值? [英] Why does the MessageBox show NULL values?
本文介绍了为什么MessageBox显示NULL值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = null;
SqlConnection connection ;
SqlDataAdapter adapter ;
DataSet ds = new DataSet();
int i = 0;
connetionString = NULL;
connection = new SqlConnection(connetionString);
try {
connection.Open();
adapter = new SqlDataAdapter("select *from New", connection);
adapter.Fill(ds);
connection.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) {
MessageBox.Show (ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
}
}
推荐答案
connetionString = NULL;
connection = new SqlConnection(connetionString);
首先,这甚至不会编译为C#是区分大小写的并且 null
关键字是小写的。
第二,在这两行中是不是有什么东西会扰乱你?
第三,为什么只是启动调试会话并看看发生了什么?
First, this would not even compile as C# is case sensitive and null
keyword is lower case.
Second, isn't there something that disturbs you in these two lines?
Third, why nost just starting a debug session and see what is going on?
这篇关于为什么MessageBox显示NULL值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文