String strcon = ConfigurationManager.ConnectionStrings["con"].ToString();
SqlConnection con;
protected void run_save(object sender, EventArgs e)
{
con = new SqlConnection(strcon);
String select = txtComand.Text;
SqlCommand cmd = new SqlCommand(select, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
gridview1.DataSource = dr;
gridview1.DataBind();
con.Close();
<asp:TextBox runat="server" ID="txtComand" TextMode="MultiLine" Height="227px"
Width="352px"></asp:TextBox>
<asp:Button runat="server" ID="idRun" OnClick="run_save" Text="RUN" />
<asp:GridView runat="server" ID="gridview1"></asp:GridView>
我在文本框中写sql comnd ..就像select * from test ..这里所有数据都显示在gridview ..但是我写select * from test where id=5 ..then 不工作