要实现查询表中的某一字段的数字插入到 textBoxbrno 中,代码如下:
private void Form1_Load(object sender, EventArgs e)
{
try
{
string strsqlconn = "server= (local);database = AIS20090413161510;trusted_connection = yes";
SqlConnection conn = new SqlConnection(strsqlconn);
string str = "Select famount from t_voucherentry where fvoucherid = 185 and fentryid =0 ";
conn.Open();
int a;
a = Int32.Parse(str);
textBoxbrno.Text = a.ToString();
SqlCommand cmd = new SqlCommand(str, conn); cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("over"); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
报错:输入字符串的格式不正确。何解?
private void Form1_Load(object sender, EventArgs e)
{
try
{
string strsqlconn = "server= (local);database = AIS20090413161510;trusted_connection = yes";
SqlConnection conn = new SqlConnection(strsqlconn);
string str = "Select famount from t_voucherentry where fvoucherid = 185 and fentryid =0 ";
conn.Open();
int a;
a = Int32.Parse(str);
textBoxbrno.Text = a.ToString();
SqlCommand cmd = new SqlCommand(str, conn); cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("over"); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
报错:输入字符串的格式不正确。何解?
str显然不是一个整数。
ussing(SqlConnection conn = new SqlConnection(strsqlconn))
{
conn.Open();
SqlCommand cmd = new SqlCommand(Sql, Connection);
SqlDataReader reader = cmd.ExecuteReader();
if(reader.Reader())
{
}
Connection.Close();
}
conn.Close();
textBoxbrno.Text = a.ToString(); 你要加油
{
try
{
string strsqlconn = "server= (local);database = AIS20090413161510;trusted_connection = yes";
SqlConnection conn = new SqlConnection(strsqlconn);
string str = "Select famount from t_voucherentry where fvoucherid = 185 and fentryid =0 ";
conn.Open();
SqlCommand cmd = new SqlCommand(str, conn);
int a = (int)cmd.ExecuteScalar();
conn.Close();
textBoxbrno.Text = a.ToString();
MessageBox.Show("over"); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
提示:指定的转换无效。为什么呢?
SELECT COUNT(*) from t_voucherentry