SQL Data Source

G

Gunawan

Hi All,

I have change select command of a sql data source when user clicking a
button


sds1.SelectCommand = "Select DivisionCode, Description FROM DivisionMst
WHERE Description LIKE @Description";
sds1.SelectParameters.Clear();
sds1.SelectParameters.Add("Description",TypeCode.String,
txtDescription.Text);

I have two question.
1. Why @Description didnot change to txtDescription value?
2. How to refresh GridView that bind to sds1 (SQL Data Source)?

TIA
Gun
 
P

Patrick.O.Ige

Gun,
pls post some snippet code and please elaborae more
if u want to refresh GridView then call DataBind
grid.Databind()
Patrick
 
G

Gunawan

Here is the code that I wrote.

if (btnFilter.Text == "Filter Off")
{ sds1.SelectCommand = "SELECT [DivisiID], [KodeDivisi],
[Deskripsi] FROM [ldc_divi_mst]"; }
else
{ string strWhere = "SELECT [DivisiID], [KodeDivisi], [Deskripsi]
FROM [ldc_divi_mst]";
if (txtKodeDivisi.Text != "")
{ strWhere += "WHERE [KodeDivisi] LIKE @KodeDivisi"; }
if (txtDeskripsi.Text != "")
{ if (txtKodeDivisi.Text != "")
{ strWhere += " AND [Deskripsi] LIKE @Deskripsi"; }
else { strWhere += "WHERE [Deskripsi] LIKE @Deskripsi"; }}

sds1.SelectCommand = strWhere;
sds1.SelectParameters.Clear();
sds1.SelectParameters.Add("KodeDivisi",TypeCode.String,
txtKodeDivisi.Text);
sds1.SelectParameters.Add("Deskripsi",TypeCode.String,
txtDeskripsi.Text);
}
sds1.Select(DataSourceSelectArguments.Empty);
gv1.DataBind();

it seems that gv1 (gridview) did not populate the right data and I think it
cause by sds1 (SQLDataSource) that does not populate the right query
(Command) and always look like this

SELECT [DivisiID], [KodeDivisi], [Deskripsi] FROM [ldc_divi_mst]WHERE
[Deskripsi] LIKE @Deskripsi

or like this

SELECT [DivisiID], [KodeDivisi], [Deskripsi] FROM [ldc_divi_mst]WHERE
[KodeDivisi] LIKE @KodeDivisi AND [Deskripsi] LIKE @Deskripsi

I would like to change parameter deskripsi and kodedivisi to a value.

Regards,
Gunawan
 

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

Members online

No members online now.

Forum statistics

Threads
474,472
Messages
2,571,834
Members
48,802
Latest member
shadowoftheunknown
Top