【发布时间】:2015-05-13 23:33:36
【问题描述】:
美好的一天!我正在尝试检索远程数据库值并显示到 Windows 窗体文本框中。
我只能将字符串值检索到文本框。但无法检索整数值。如何检索整数值。
TabPage tpge = new TabPage();
tpge = tabControl1.SelectedTab;
SqlConnection cn = null;
string connectString = "";
SqlCommand cmd = null;
SqlDataReader rdr = default(SqlDataReader);
connectString = string.Format("Data Source = IP,1433;Initial Catalog=idb;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD;");
cn = new SqlConnection(connectString);
try
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
}
catch (Exception ex)
{
MessageBox.Show("Open Error");
MessageBox.Show(ex.Message);
}
try
{
MessageBox.Show("1");
cmd = new SqlCommand("select * from tAerator1", cn);
cmd.CommandType = CommandType.Text;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
txtAEremrk.Text = rdr.GetString(rdr.GetOrdinal("fldAEremrk"));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
cn.Close();
【问题讨论】:
标签: c#