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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing parameter in selectcommand of dataadapter

Status
Not open for further replies.

vaichi123

Programmer
Dec 2, 2006
20
US
da = New SqlDataAdapter("Select Busunit from Product where name = @prod", dbcon)
da.SelectCommand.Parameters.Add("@prod",sqlDbType.VarChar, 24).Value = "prod"
da.Fill(ds, "Product")

In the above code, I am passing the value of prod to the sql in da and then filling the dataset in the last line.
I want to know if this is the right way to be able to pass a value in to sql in the first line above.
 
I use the Parameter.Add command in this way

.Parameters.Add("@prod","Prod")
First Name, then value

The '.Value = "prod"' in your code is used for the returning value (i think)

I use caps for Parameter names as well, I don't if it something i just picked up or if its the way you have to do it (@PROD)?
 
Hello,

I like to do it this this method, i think it is much more clear.

Code:
dim cmd as new sqlcommand()
dim da as new sqldataadapter()

dim pProd as new sqlParameter()
pProd.parametername = "@Prod"
pProd.sqldbtype = sqldbtype.varchar()
pProd.direction = ? either input, or output or both
pProd.value = prod
cmd.parameter.add(pProd)

da.selectCommand = cmd.
da.fill(ds)

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top