新手请教 类型转换问题 先谢了 InsertCmd = string.Format("insert into CTtest(Testcurrent,CurrentChannel) Values({0}, {1})", testCurrent, currentChannel); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谢谢楼上的热心帮助,可能使我没说清楚,好像你理解的不是一个问题我的问题是:在Form的文本框中输入的是字符型,要怎样转换成float型?比如我输入小数,怎样写添加的代码中Values参数呀? 就象转换成int型,int.parse(str) 建议你使用TryParse();参考如下代码:if (!float.TryParse(textBox1.Text, out testCurrent)){ MessageBox.Show("Error"); return;}if (!float.TryParse(textBox2.Text, out currentChannel)){ MessageBox.Show("Error"); return;}InsertCmd = string.Format("insert into CTtest(Testcurrent,CurrentChannel) Values({0}, {1})", testCurrent, currentChannel); “float中并不包含对TtyParse的定义“应该怎样定义呀?testCurrent currentChannel在类或命名空间不存在,怎么回事?我真得不太懂,还请楼上的帮忙帮到底,麻烦给讲详细一点好吗?谢谢了!刚学所以不太懂! 大概是这样float testCurrent = float.Parse(textBox1.Text);float currentChannel = float.Parse(textBox2.Text);InsertCmd = string.Format("insert into CTtest(Testcurrent,CurrentChannel) Values({0}, {1})", testCurrent, currentChannel); Convert.ToSingle方法,和TryParse一样 用C#怎么实现操作EXCEL表 VB6語句轉C#語句 EXCEL 复制 SendMessage listview LVM_FINDITEM 求救! 急~ 一个关于杀进程的问题 在vs.net中进行C# windows编程,如何定义一个config文件,用于存储数据库连接信息 [求助]数据集插入到数据库中表的问题!!! 急急!!打开IE自动进入http://4-counter.com/,而且自动增加收藏夹链接位置,修改注册表无效,将注册表恢复还是没有用 急问:C#能工程能编译为WIN32 DLL么 有关DropDownList的问题? 关于线程问题 mm高分求救!decimal的精度問題?
我的问题是:
在Form的文本框中输入的是字符型,要怎样转换成float型?比如我输入小数,怎样写添加的代码中Values参数呀?
就象转换成int型,int.parse(str)
参考如下代码:if (!float.TryParse(textBox1.Text, out testCurrent))
{
MessageBox.Show("Error");
return;
}if (!float.TryParse(textBox2.Text, out currentChannel))
{
MessageBox.Show("Error");
return;
}InsertCmd = string.Format("insert into CTtest(Testcurrent,CurrentChannel) Values({0}, {1})", testCurrent, currentChannel);
testCurrent currentChannel在类或命名空间不存在,怎么回事?
我真得不太懂,还请楼上的帮忙帮到底,麻烦给讲详细一点好吗?
谢谢了!刚学所以不太懂!
float testCurrent = float.Parse(textBox1.Text);
float currentChannel = float.Parse(textBox2.Text);InsertCmd = string.Format("insert into CTtest(Testcurrent,CurrentChannel) Values({0}, {1})", testCurrent, currentChannel);