Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure expects a parameter which was not supplied.

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hello, All.

Is there a way to make these two lines of code one line.

Code:
comm.Parameters.Add(new SqlParameter("@p1",SqlDbType.VarChar,3));
comm.Parameters["@p1"].Value = textBox1.Text;

Thought it would be simple.... like

Code:
comm.Parameters.Add(new SqlParameter("@p1",SqlDbType.VarChar,3).Value = textBox1.Text);

but that doesn't compile.

Visual Studio 2008. C#. Sql Server 2008.
The code is in a 'using (new SqlCommand comm)' clause which is in a Using Connection clause. Trying to utilize the dispose() benefits of the using clause.


Thanks, Everyone.
Patrick B
 
Code:
comm.Parameters.Add(new SqlParameter("@p1", textBox1.Text));
[/code

Rhys

"[i]Technological progress is like an axe in the hands of a pathological criminal[/i]"
"[i]Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe[/i]"
[b]Albert Einstein[/b]
 
..or...
Code:
comm.Parameters.Add(new SqlParameter { ParameterName = @"@p1", Value = textBox1.Text, SqlDbType = SqlDbType.VarChar });

Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top