2016-08-03 10 views
1

이 코드를 실행할 때마다이 오류가 계속 발생하며 실제로 여기에서 누락 된 내용을 찾을 수 없습니다. 미리System.Data.OleDb.OleDbException 'System.Data.dll에서 발생했지만 사용자 코드에서 처리되지 않았습니다.

의 오류 : 'System.Data.OleDb.OleDbException는'가 system.data.dll 발생하지만 사용자 코드

추가 정보 처리되지 않은 조건 식에서 데이터 형식이 일치한다.

프론트 엔드 코드 :

<asp:GridView ID="gvFunction" runat="server" AutoGenerateColumns="false" CssClass="Grid" 
    DataKeyNames="ID" OnRowDataBound="OnRowDataBound"> 
    <Columns> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <img alt = "" style="cursor: pointer" src="images/plus.png" /> 
       <asp:Panel ID="pnlOrders" runat="server" Style="display: none"> 
        <asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid"> 
         <Columns> 
          <asp:BoundField ItemStyle-Width="150px" DataField="ID" HeaderText="ID" /> 


          <asp:BoundField ItemStyle-Width="150px" DataField="FunctionDate" HeaderText="Function Date" /> 
          <asp:BoundField ItemStyle-Width="150px" DataField="FunctionTime" HeaderText="Function Time" /> 
          <asp:BoundField ItemStyle-Width="150px" DataField="CelebrateName" HeaderText="Celebrate Name" /> 


         </Columns> 
        </asp:GridView> 
       </asp:Panel> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:BoundField ItemStyle-Width="150px" DataField="ID" HeaderText="ID" /> 
     <asp:BoundField ItemStyle-Width="150px" DataField="FunctionDate" HeaderText="Function Date" /> 
     <asp:BoundField ItemStyle-Width="150px" DataField="CelebrateName" HeaderText="Celebrate Name" /> 

    </Columns> 
</asp:GridView> 

돌아 가기 종료 코드 :

귀하의 ID 필드를 int 또는 문자열 필드
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Configuration; 
using System.Data.OleDb; 
using System.Data; 

namespace mntfinal 
{ 
    public partial class editreport : System.Web.UI.Page 
    { 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 

      gvFunction.DataSource = GetData("select ID, 
      FunctionDate, CelebrateName from function"); 
      gvFunction.DataBind(); 
     } 
    } 
    private static DataTable GetData(string query) 
    { 
     string strConnString = ConfigurationManager.ConnectionStrings 
     ["MandapamDatabase"].ConnectionString; 
     using (OleDbConnection con = new OleDbConnection(strConnString)) 
     { 
      using (OleDbCommand cmd = new OleDbCommand()) 
      { 
       cmd.CommandText = query; 
       using (OleDbDataAdapter sda = new OleDbDataAdapter()) 
       { 
        cmd.Connection = con; 
        sda.SelectCommand = cmd; 
        using (DataSet ds = new DataSet()) 
        { 
         DataTable dt = new DataTable(); 
         sda.Fill(dt); 
         return dt; 
        } 
       } 
      } 
     } 
    } 

    protected void OnRowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      string ID = gvFunction.DataKeys[e.Row.RowIndex].Value.ToString(); 
      GridView gvOrders = e.Row.FindControl("gvOrders") as GridView; 
      gvOrders.DataSource = GetData(string.Format("select ID,FunctionDate,FunctionTime,CelebrateName from function where ID='{0}'", ID)); 
      gvOrders.DataBind(); 
     } 
    } 
} 
} 

답변

1

The criteria expression is the part of the query containing the conditions, as in WHERE .

문제는 where 절에있는 것처럼 보입니다. ID 열 값 (정수 일 수 있음)과 문자열을 비교하려고합니다. 내가 주위 {0} 작은 따옴표 제거 한이 시도 :

는 매우 거친 추측이
protected void OnRowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      string ID = gvFunction.DataKeys[e.Row.RowIndex].Value.ToString(); 
      GridView gvOrders = e.Row.FindControl("gvOrders") as GridView; 
      gvOrders.DataSource = GetData(string.Format("select ID,FunctionDate,FunctionTime,CelebrateName from function where ID={0}", ID)); 
      gvOrders.DataBind(); 
     } 
    } 
+1

내 문제를 해결해 주셔서 고마워요. –

0

인가? 문자열을 int로 변경하고 {0} 주위의 따옴표를 제거하십시오.

+0

자동 번호가 있으며 그 int가 맞습니까? 그게 가능하다면 내가 어떻게 가치를 대체 할 수 있는지 말해 주실 수 있습니다. 사촌 꽤 아마추어 임 –

+0

@sachin이 제공 한 코드를 먼저 시도해보십시오. 그 정도면 충분합니다. – Dennisvdh

+0

정말 도움이 많이 도움 주셔서 감사합니다 –

0

, 해당 문자열 ID가 뭔가 이상한 포함을 .. 예를 "널 (null)"

체크 무엇 및 String.format ("선택 ID, FunctionDate, FunctionTime, ID = '{0}'기능에서 CelebrateName", ID) 의 모습과 같아요, 여기에 최종 SQL 문을 게시 우리는 여기서 원인을 볼 수 있습니다.