.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 8th, 2008, 10:31 AM
randallj2877 randallj2877 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 107 randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 7 h 21 m 44 sec
Reputation Power: 9
Unhappy SqlException: The parameterized query ## expects parameter ##, which was not supplied

I have the following code:

PHP Code:
 1            public void UpdateTableInfo(string commandstring dbTableNameDataTable dataTableIList<stringparameters)
2            {
3                _dataAdapter.InsertCommand = new SqlCommand(@command);
4                IList<SqlDbTypetableColumnTypes GetTableColumnTypes(dbTableName);
5                for (int i 0parameters.Counti++)
6                {
7                    _dataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@" parameters[i], tableColumnTypes[i]));
8                }
9                SqlConnection conn DbConnection;
10               _dataAdapter.InsertCommand.Connection conn;
11               using (conn)
12               {
13                   _dataAdapter.Update(dataTable.DataSetdbTableName);
14               }
15           


...which produces the following SqlException exception, on Line 13:

Quote:
{"The parameterized query '(@Value0 varchar(8000),@Value1 ntext,@Value2 decimal(29,0))INSER' expects the parameter '@Value0', which was not supplied."}


I can't figure out what the problem is here.

The connection string (DbConnection) is valid. The 'command' argument of the method evaluates to "INSERT INTO Catalog VALUES (@Value0,@Value1,@Value2)". The 'parameters' collection (in the method argument) returns {"Value0","Value1","Value2"}. The collection 'tableColumnTypes' returns a valid list of SqlDbType objects, that correspond correctly to the respective parameter names in the _dataAdapter.InsertCommand.Parameters collection (the SqlDbType objects also correspond correctly to the column data types in my database table). The dataTable and dbTableName arguments of the method are also valid.

Am I forgetting anything here? ;-)

I did consider the possibility of one of my parameter names being an SQL keyword (i.e, "Value"). But by using "Value0","Value1", etc., I think I have avoided this problem?

Also, the SQL table column names are "ID" [varchar(50)], "Description" [ntext], and "Price" [decimal(18,2)]. There is no primary key, but "ID" could easily be made the primary key.

Thanks for any help.
__________________
__________________
Regards, R.J.

Media Moguls
Cleveland, Ohio Web Site Design and Application Development

Reply With Quote
  #2  
Old May 9th, 2008, 02:21 PM
randallj2877 randallj2877 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 107 randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 7 h 21 m 44 sec
Reputation Power: 9
Resolved.

PHP Code:
public void UpdateTableInfo(string commandstring dbTableNameDataTable dataTableIList<stringparameters)
        {
            
_dataAdapter.InsertCommand = new SqlCommand(@command);
            
IList<SqlDbTypetableColumnTypes GetTableColumnTypes(dbTableName);
            for (
int i 0parameters.Counti++)
            {
                
_dataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@" parameters[i], tableColumnTypes[i]));
                
_dataAdapter.InsertCommand.Parameters["@" parameters[i]].SourceVersion DataRowVersion.Current;
                
_dataAdapter.InsertCommand.Parameters["@" parameters[i]].SourceColumn dataTable.Columns[i].ColumnName;
            }
            
SqlConnection conn DbConnection;
            
_dataAdapter.InsertCommand.Connection conn;
            
using (conn)
            {
                
_dataAdapter.Update(dataTable.DataSetdbTableName);
            }
        } 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > SqlException: The parameterized query ## expects parameter ##, which was not supplied


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway