InsertCmd = string.Format("insert into CTtest(Testcurrent,CurrentChannel) Values({0}, {1})", testCurrent, currentChannel);

解决方案 »

  1.   

    谢谢楼上的热心帮助,可能使我没说清楚,好像你理解的不是一个问题
    我的问题是:
    在Form的文本框中输入的是字符型,要怎样转换成float型?比如我输入小数,怎样写添加的代码中Values参数呀? 
    就象转换成int型,int.parse(str)
      

  2.   

    建议你使用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);
      

  3.   

    “float中并不包含对TtyParse的定义“应该怎样定义呀?
    testCurrent  currentChannel在类或命名空间不存在,怎么回事?
    我真得不太懂,还请楼上的帮忙帮到底,麻烦给讲详细一点好吗?
    谢谢了!刚学所以不太懂!
      

  4.   

    大概是这样
    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);
      

  5.   

    Convert.ToSingle方法,和TryParse一样