'Some Decimal Value(20.12134)'附近的语法不正确 [英] Incorrect Syntax near 'Some Decimal Value(20.12134) '

查看:80
本文介绍了'Some Decimal Value(20.12134)'附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的C#代码



THIS IS MY C# CODE

private void button5_Click(object sender, EventArgs e)
        {
            string connection = @"Data Source=(local);Initial Catalog=Project;Integrated        Security=True";
            SqlConnection sc = new SqlConnection(connection);
            string query2 = "insert into dbo.temp1 (weight,height,bmi)values('" + this.WeightTxt.Text + "','" + this.heightTxt.Text+ "','"+this.ResultTxt.Text+"'";
            SqlConnection conn = new SqlConnection(connection);
            SqlCommand cmdDataBase2 = new SqlCommand(query2, conn);
            SqlDataReader myReader;
            try
            {
                conn.Open();
                myReader = cmdDataBase2.ExecuteReader();
                MessageBox.Show("Data Saved Bacchi..");
                
                while (myReader.Read())
                {

                }
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }





这是我的数据库创建声明





THIS IS MY DATABASE CREATE STATEMENT

create table temp1
(
weight numeric(3),
height numeric (3),
bmi numeric(7,7)
);

推荐答案

查看您的查询,它缺少结束)的值块。

尝试以下并检查是否有效...





see your query it missing the closing ) for the values block.
try below and check if that works...


string query2 = "insert into dbo.temp1 (weight,height,bmi)values('" + this.WeightTxt.Text + "','" + this.heightTxt.Text+ "','"+this.ResultTxt.Text+"'");





当你宣布桌子时,请使用数值数据类型正确。它可以像下面

Hi
When you are declaring table the table, make use of numeric data type properly. It can be like below
create table temp1
(
weight numeric(3,2),
height numeric (3,2),
bmi numeric(7,7)
);





一般来说,体重和身高都有十进制值。因此,当您将数据插入到已声明的表中时(我正在引用您编写的表语法),我们将得到以下错误

将数值转换为数字的算术溢出错误数据类型为数字。



我认为问题在于表格声明



Generally weight and height have decimal values. So when you are inserting data into the table that you have declared (i'm refering to the table syntax you have writen), we will get the below error
Arithmetic overflow error converting numeric to data type numeric.

I think the problem is with table declaration


这篇关于'Some Decimal Value(20.12134)'附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆