3
Answers

passing a different sql string to DataAdapter each time i click a button

eksypnos123

eksypnos123

20y
2.3k
1
private void button1_Click(object sender, System.EventArgs e) { ds.Tables.Clear(); da.SelectCommand=new SqlCommand(textBox1.Text,sqlConnection1); da.Fill(ds,"myTable"); dataGrid1.SetDataBinding(ds,"myTable"); } I have a form with a textBox1, a dataGrid1 and a button1. In the textBox1 I write some sql code and I want to see the output in the grid. ds is a dataset and da is a dataAdapter that were instantiated once in the constructor without any parameters. (ds=new DataSet(), da=New DataAdapter()). My problems is that this code seems to execute only the first time I click the button. After the first time the datagrid doesn't change although i put different sql code in the textBox. Can somebody tell me why is this happening?
Answers (3)
0
Amit Choudhary

Amit Choudhary

NA 27.7k 3m 14y
for your second problem of ActiveTabIndex

you should go through my article on
Enhancing the functionality of Ajax Tab Control

it'll surely help you

Please Don't forget to mark "Do you like this post" if it helps.
0
Amit Choudhary

Amit Choudhary

NA 27.7k 3m 14y
hi friend,

there is two solution for this problem.

1. set EnableEventValidation="false" attribute of aspx <%@page--%> tag .

2. Or if you have some code written inside the page_load event if not necessary to call the code at postback then

  if(!Page.IsPostBack)
{
   // you complete code inside page_load event will go here
}

Any of the above method will solve your problem.. but choose second one carefully it may change your behavior of program while postback.

Please Don't forget to mark "Do you like this post" if it helps.
0
Dipa Ahuja

Dipa Ahuja

NA 4.1k 612.6k 14y
There may me some mistake in your code.. you have to write your code to find the mistake