views:

87

answers:

2

im trying to bind a a sql statement to a datagrid.

having some trouble:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<script runat="server">

    private const string _strConStr = "Data Source=Sqlserver01; Initial Catalog=Igors_Test; Integrated Security=SSPI";
    private const string _strSql = "Selct * from stotickets where [Status] = 'Active'";
    private SqlDataAdapter da;
    private DataSet ds;

    void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
            dgTicketInfo.DataSource = ds;
            dgTicketInfo.DataBind();
        }

    }

    void LoadData()
    {
        da = new SqlDataAdapter(_strSql, _strConStr);
        ds = new DataSet();
        da.Fill(ds);
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
         <asp:DataGrid runat="server" ID="dgTicketInfo" />
    </div>
    </form>
</body>
</html>

error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Incorrect syntax near '*'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '*'.

Source Error: 


Line 27:         da = new SqlDataAdapter(_strSql, _strConStr);
Line 28:         ds = new DataSet();
Line 29:         da.Fill(ds);
Line 30:     }
Line 31: 

Source File: d:\http\netdev\Grid_Stoenv.aspx    Line: 29 

Stack Trace: 


[SqlException (0x80131904): Incorrect syntax near '*'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +212
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2811
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +58
   System.Data.SqlClient.SqlDataReader.get_MetaData() +112
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6281668
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6282737
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +424
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +211
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +19
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +19
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +221
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +573
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +166
   ASP.grid_stoenv_aspx.LoadData() in d:\http\netdev\Grid_Stoenv.aspx:29
   ASP.grid_stoenv_aspx.Page_Load(Object sender, EventArgs e) in d:\http\netdev\Grid_Stoenv.aspx:18
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927 
+1  A: 

change this line

private const string _strSql = "Selct * from stotickets where [Status] = 'Active'";

to

private const string _strSql = "Select * from stotickets where [Status] = 'Active'";
RRUZ
+1  A: 

you spelled "Select" incorrectly.

Selct * from ...

should be

Select * from ...

rockinthesixstring
On a side note, You should really consider making the jump to Linq to SQL or Entity Framework. Inline SQL is very passé. You'll find your development speed increase ten fold with an ORM.
rockinthesixstring