Command or Adapter weird error

D

daveL

I get the Error below, when all is Correct

Parameterized Query '(@MemberId int,@InvoiceRefNo varchar(25)) Update
Members Set In' expects parameter @InvoiceRefNo, which was not supplied.

//code that runs
SqlCommand Cmd = new SqlCommand();
Cmd.Parameters.Clear();



Cmd.CommandText = " Update Members Set
InvoiceRefNo=@InvoiceRefNo Where Memberid= @Memberid";

Cmd.Parameters.Add("@MemberId", SqlDbType.Int);
Cmd.Parameters.Add("@InvoiceRefNo", SqlDbType.VarChar, 25);
Cmd.Parameters["@InvoiceRefNo"].SourceColumn = "InvoiceRefNo";

Cmd.CommandType = CommandType.Text;
Cmd.Connection = SqlConn1.Conn;
Cmd.Parameters["@MemberId"].SourceColumn = "Memberid";

dtMembers.TableName = "Members";


SqlDataAdapter ad = new SqlDataAdapter();
ad.UpdateCommand=Cmd;

Console.WriteLine(ad.UpdateCommand);


ad.DeleteCommand = null;
try
{
this.SqlConn1.Open();
ad.Update(this.dtMembers);
this.SqlConn1.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);

}

}
DaveL
 
D

daveL

i was thinking the Same Thing...somthing in the Command Text.....
I made a Second Command with new variables (ie adapter, command object etc,
worked just fine)
i just dont want to quit till i figure out what the problem is with this
code,

Thanks alot peter,
I'll keep pluging away

DaveL
 
J

Jeff Johnson

//code that runs
SqlCommand Cmd = new SqlCommand();
Cmd.Parameters.Clear();

An observation: you have JUST created a brand new SqlCommand object. There
is no reason to clear the Parameters collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top