public partial class Fr_Main : Form
{
//SqlConnection objsqlconnection;
//SqlDataAdapter objsqldataadapter;
private SqlConnection objsqlconnection;
private SqlCommand objsqlcommand;
private string inscmd;
private string sun;
public Fr_Main()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“baidatongDataSet.h_xiaofeijilu”中。您可以根据需要移动或移除它。
this.h_xiaofeijiluTableAdapter.Fill(this.baidatongDataSet.h_xiaofeijilu);
//链接金蝶数据库
objsqlconnection = new SqlConnection("server =61.150.91.149;database = baidatong;uid =baidatong_f;pwd =cbG62lQIlZ ");
sun ="select sum(xiaofeijine) from h_xiaofeijilu";
suu = (int)sun;
string 无法转换为 int
提供的两种方法都用了
int.Parse()
System.Convert.ToIntXX() 都不行
高手有好办法吗?
{
//SqlConnection objsqlconnection;
//SqlDataAdapter objsqldataadapter;
private SqlConnection objsqlconnection;
private SqlCommand objsqlcommand;
private string inscmd;
private string sun;
public Fr_Main()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“baidatongDataSet.h_xiaofeijilu”中。您可以根据需要移动或移除它。
this.h_xiaofeijiluTableAdapter.Fill(this.baidatongDataSet.h_xiaofeijilu);
//链接金蝶数据库
objsqlconnection = new SqlConnection("server =61.150.91.149;database = baidatong;uid =baidatong_f;pwd =cbG62lQIlZ ");
sun ="select sum(xiaofeijine) from h_xiaofeijilu";
suu = (int)sun;
string 无法转换为 int
提供的两种方法都用了
int.Parse()
System.Convert.ToIntXX() 都不行
高手有好办法吗?
我倒,你都没有执行SQL语句,sun 就一个字符串怎么可能转换成int...
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“baidatongDataSet.h_xiaofeijilu”中。您可以根据需要移动或移除它。
this.h_xiaofeijiluTableAdapter.Fill(this.baidatongDataSet.h_xiaofeijilu);
//链接金蝶数据库
objsqlconnection = new SqlConnection("server =61.150.91.149;database =baidatong;uid =baidatong_f;pwd =cbG62lQIlZ ");
sun ="select sum(xiaofeijine) from h_xiaofeijilu";
SqlCommand cmd = new SqlCommand(sun,objsqlconnection);
objsqlconnection.Open();
suu=Convert.ToInt32(cmd.ExecuteScalar());
objsqlconnection.Close();
string sql = "select sum(xiaofeijine) from h_xiaofeijilu";
int count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.Conn, CommandType.Text, sql));
if (count > 0)
flag = true; else
flag = false; using(SqlConnection thisConnection = new SqlConnection(@""))
{ thisConnection.Open();
SqlCommand cmd= thisConnection.CreateCommand();
thisCommand.CommandText = "select sum(xiaofeijine) from h_xiaofeijilu"
object countResult =cmd.ExecuteScalar(); thisConnection.Close();
}
suu = (int)sun;
晕 没执行那
收集结果的sun换一个新定义的int型变量
int.TryParse("你要转换的字符串",out D);
转换失败时输出D,成功就不用说了