SQL错误:参数化查询...表示参数

时间:2012-10-30 17:48:30

标签: sql sql-server

我在将日志文件部分转换为SQL DateTime时遇到问题,并且发现更好的解决方案是让我的日期字段由数据库而不是代码生成(使用GETDATE())。

我从插入中删除了日期字段,但现在我收到此错误:

  

错误:参数化查询'(@ station int,@ indoor_temp float,@ outdoor_temp float,@ dewpoint f'需要参数'@wind_direction_text',这是未提供的。

它提供的那个值是提供的,插入仍然成功并插入数据库记录的更奇怪!

我想弄清楚为什么我会得到这些例外!

这是我的代码:

var dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;

dataCommand.Parameters.AddWithValue("@station", _stationId);
dataCommand.Parameters.AddWithValue("@indoor_temp", _indoorTemp);
dataCommand.Parameters.AddWithValue("@outdoor_temp", _outdoorTemp);
dataCommand.Parameters.AddWithValue("@dewpoint", _dewPoint);
dataCommand.Parameters.AddWithValue("@rel_humidity_indoor", _relHumidityIndoor);
dataCommand.Parameters.AddWithValue("@rel_humidity_outdoor", _relHumidityOutdoor);
dataCommand.Parameters.AddWithValue("@wind_speed", _windSpeed);
dataCommand.Parameters.AddWithValue("@wind_direction_degrees", _windDirectionDegrees);
dataCommand.Parameters.AddWithValue("@wind_direction_text", _windDirectionText);
dataCommand.Parameters.AddWithValue("@wind_chill", _windChill);
dataCommand.Parameters.AddWithValue("@rain1h", _rain1H);
dataCommand.Parameters.AddWithValue("@rain24h", _rain24H);
dataCommand.Parameters.AddWithValue("@rain_total", _totalRain);
dataCommand.Parameters.AddWithValue("@relative_pressure", _relativePressure);
dataCommand.Parameters.AddWithValue("@tendency", _tendency);
dataCommand.Parameters.AddWithValue("@forecast", _forecast);

dataCommand.CommandType = CommandType.Text;
dataCommand.CommandText =
                         "INSERT INTO"
                         + " dbo.WeatherData(station_id, indoor_temp, outdoor_temp, dewpoint," +
                            "rel_humidity_indoor, rel_humidity_outdoor, wind_speed, wind_direction_degrees," +
                            "wind_direction_text, wind_chill, rain1h, rain24h, rain_total, relative_pressure," +
                            "tendency, forecast)"
                            + "VALUES " +
                            "(@station, @indoor_temp, @outdoor_temp, @dewpoint, @rel_humidity_indoor," +
                            "@rel_humidity_outdoor, @wind_speed, @wind_direction_degrees," +
                            "@wind_direction_text, @wind_chill, @rain1h, @rain24h, @rain_total," +
                            "@relative_pressure, @tendency, @forecast)";

// execute the insert command
dataCommand.ExecuteNonQuery();

感谢您的帮助!

0 个答案:

没有答案
相关问题