|
Hello,
I have been creating a simple gridview in an asp.net application connected to sql server. Everthing works fine on the local development site, when I deploy I get the following error.
Invalid column name 'ClientID'.
Invalid column name 'ContractorID'.
Invalid column name 'ProjectType'.
Invalid column name 'HideProject'.
Invalid column name 'StartOnSite'.
Invalid column name 'Completion'.
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: Invalid column name 'ClientID'.
Invalid column name 'ContractorID'.
Invalid column name 'ProjectType'.
Invalid column name 'HideProject'.
Invalid column name 'StartOnSite'.
Invalid column name 'Completion'.
The gridview has been created using visual studio 2008, without modification, and points to a view based on 3 tables. I have re-created both the gridview and tables several times. The view was scripted from the local sql server on the remote server, using Create View with SET QUOTED_IDENTIFIER ON and also turned off. I have removed all parameters, so theres nothing that could trip up the query. The query runs fine on the remote server when I look at it with Management Server. I have also tried changing all the fields on the gridview to template fields, so I can see the bindings and check for upper and lower cases, and everything is fine. I have checked through lots of articles and this is usually due to missing columns on the view or table, or upper and lower cases in the mark up; but they are all fine and work in the development environment?
This is driving me mad. Since the view runs on the server without problems, it must be the asp.net gridview thats tripping out. But I can't see it.
Here is the gridview markup.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" <br />
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" <br />
CellPadding="3" CssClass="menutxt" DataKeyNames="ProjectID" <br />
DataSourceID="ProjectListing" GridLines="Vertical"><br />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" /><br />
<Columns><br />
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" ReadOnly="True" <br />
SortExpression="ProjectID" /><br />
<asp:BoundField DataField="ClientID" HeaderText="ClientID" <br />
SortExpression="ClientID" /><br />
<asp:BoundField DataField="ProjectName" HeaderText="ProjectName" <br />
SortExpression="ProjectName" /><br />
<asp:BoundField DataField="ContractorID" HeaderText="ContractorID" <br />
SortExpression="ContractorID" /><br />
<asp:BoundField DataField="ProjectType" HeaderText="ProjectType" <br />
SortExpression="ProjectType" /><br />
<asp:BoundField DataField="Description" HeaderText="Description" <br />
SortExpression="Description" /><br />
<asp:CheckBoxField DataField="HideProject" HeaderText="HideProject" <br />
SortExpression="HideProject" /><br />
<asp:BoundField DataField="StartOnSite" HeaderText="StartOnSite" <br />
SortExpression="StartOnSite" /><br />
<asp:BoundField DataField="Completion" HeaderText="Completion" <br />
SortExpression="Completion" /><br />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" <br />
SortExpression="CompanyName" /><br />
</Columns><br />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" /><br />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /><br />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /><br />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /><br />
<AlternatingRowStyle BackColor="#DCDCDC" /><br />
</asp:GridView><br />
<asp:SqlDataSource ID="ProjectListing" runat="server" <br />
ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>" <br />
SelectCommand="SELECT [ProjectID], [ClientID], [ProjectName], [ContractorID], [ProjectType], [Description], [HideProject], [StartOnSite], [Completion], [CompanyName] FROM [About_VProjectList]"><br />
</asp:SqlDataSource>
What school boy error am I making that I just can't see?
|
|
|
|
|
Have you checked the conneciton string? Is it pointed to the correct database?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark,
Thanks for the reply, I have now sorted the problem. I stopped, grabbed a beer and started again from scratch. The problem was the order of the tables as I brought them into the view. The main table with Project information was not selected first. This obvuiosly effects the order of the inner joins. It seems the remote database is more sensitive than the development database. It worked locally, but crashed on the server. Opening both Visual Studio and Management Studio, I created the views together, selecting the main table first, then the forein key tables, making sure to select the columns in the same order. This appears to have resolved the error. I am now going to carry on with the beer. Regards, Tony
|
|
|
|
|
|
Hi.
Please help me with this as i am also getting the same error.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Prod_code" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Prod_code" HeaderText="Prod_code" ReadOnly="True"
SortExpression="Prod_code" />
<asp:BoundField DataField="Prod_cate_id" HeaderText="Prod_cate_id"
SortExpression="Prod_cate_id" />
<asp:BoundField DataField="Prod_name" HeaderText="Prod_name"
SortExpression="Prod_name" />
<asp:BoundField DataField="Prod_desc" HeaderText="Prod_desc"
SortExpression="Prod_desc" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="image1" runat="server" ImageUrl='<%#"Handler.ashx?Prod_code="+Eval("Prod_code") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:centurydbConnectionString2 %>"
SelectCommand="SELECT [Prod_code], [Prod_cate_id], [Prod_name], [Prod_desc], [Prod_image], [Price], [Status] FROM [Prod_detail1]">
</asp:SqlDataSource>
Please help me with this error................................
|
|
|
|
|
how can we check whether a list item in radio button list is selected or not,
without using for each loop or javascript
Known is a drop, unknown is an ocean
-- Modified Sunday, April 18, 2010 6:24 AM
|
|
|
|
|
Are you trying at serverside. If yes, then you can get via prperty SelectedItem.It returns null if no item is selected.
Are you looking for somthing else?
|
|
|
|
|
You can check it with SelectedIndex Properties.
if (RadioButtonList1.SelectedIndex > -1)
{
Response.Write(RadioButtonList1.SelectedIndex.ToString());
}
else
{
Response.Write("No Item Is Selected");
}
Cheers !
Abhijit Jana | MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello, This Is Vikash Gohil.
I need some guideline/help on the following issue.
I have a webpage with a function written on Page_load event which takes the arguments from url using querystring and prints a single line on the page after execution of the function.
Now as per my knowledge, if i need to execute that function, i need to provide the full url in the address bar of the browser along with arguments needed.
Now what i want is, I dont want my webapp to redirect to that webpage but still need the function on that page, to get executed with the dynamically passed argument values.
Now, in first place, is this thing possible?
If yes, then can someone tell me the way to do it.
if no, then can i achieve this functionality in some other way?
All i want is the user must not be redirected, but still want to execute the function on another page.
Awaiting a reply soon, any help would be highly appreciated.
Thanks in Advance.
|
|
|
|
|
Whatever code you have written in the Page_Load event of the webpage should be removed and kept in a method in some other class. You can have something like Common.cs where you can put all the methods which are to be used across the webpages.
|
|
|
|
|
Hello, danish.
Thanks for your response.
But the problem is I cannot change any code as it is not my creation, it is like a 3rd party Control so i can only use it and not change anything.
But anyway thanks for the reply.
|
|
|
|
|
|
Hello, Chetan.
Thanks for your reply.
But what I want is not hiding the actual URL from the user.
My actual requirement is to execute code written in page_load event on another page without redirecting to that page.
Is this thing possible?
Please reply.
|
|
|
|
|
Use Server.Transfer
Best Regards,
Chetan Patel
|
|
|
|
|
hi Friend's
Suppose i have one application which having session time out set as 45 min, now the scenario is suppose one user login and activate that session and close the browser without login off.
what happen to that session?
Is that session automatically terminate by garbage collection?
Or still remain active and if so then how to handle this session?
Thank's and regard's
Sasmi
|
|
|
|
|
Session will kill automatically after the defined time frame.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Session is maintained on server. So you don't need to worry about session time out. If the session is active and user close the browser, the particular session will automatically goes down when it reaches to session time out.
Now, if you want to perfrom some operation on session timeout or you want to clear the data base information while user log off the application, you need to handle the Session_End Event in global.asax and you may need to trap the browser close also.
Cheers !
Abhijit
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
i have a gridview that contains a template field in my page. in this template field there is a combobox and a label. i want to change the text of the label when the combo box is changed, so when i'm trying to access this label in the selectedindexchange event it doesn't show the label name. dose any one can help me with this.
|
|
|
|
|
How are you accessing your label?
|
|
|
|
|
|
Hi,
this should work (replace ids):
protected void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList comboBox = (DropDownList)sender;
GridViewRow row = (GridViewRow)comboBox.NamingContainer;
Label myLabel = row.FindControl("myLabel");
myLabel.Text = "myText";
}
|
|
|
|
|
Hi all,
I am creating a dynamic data website.I have created two .dbml files with different tables.And i have registered in the Global.asax creating the two objects with MetaModel as model and model1.
Now i am having two pages and in one page i want to use tables related to model and in the other pages tables related to model1.
How can i do it ?
Thanks in advance.
|
|
|
|
|
Hello guys,
im trying to bind XML file into a Datagrid and editing it..
this is my XML file
<?xml version="1.0" encoding="utf-8"?>
<chores>
<day label="111" title="asdasd">
<job a="2" b="22" c="22" d="22" />
<job a="2" b="22" c="22" d="22" />
</day>
</chores>
My ASPX Page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EditTables.aspx.cs" Inherits="EditTables" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style type="text/css">
.style1 { width: 100%; } </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table class="style1">
<tr>
<td>
<br />
<br />
Edit your Products tables<br />
</td>
</tr>
<tr>
<td>
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" oncancelcommand="DataGrid1_CancelCommand" ondeletecommand="DataGrid1_DeleteCommand" oneditcommand="DataGrid1_EditCommand" onpageindexchanged="DataGrid1_PageIndexChanged" onupdatecommand="DataGrid1_UpdateCommand" AutoGenerateColumns="False" Width="890px">
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateColumn HeaderText=" label">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "label")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxTitle"
Text='<%# DataBinder.Eval(Container.DataItem, "label") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="title">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "title")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxTitle"
Text='<%# DataBinder.Eval(Container.DataItem, "title") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="כמות">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "a")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxAmount"
Text='<%# DataBinder.Eval(Container.DataItem, "a") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="מחירון">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "b")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxPrice"
Text='<%# DataBinder.Eval(Container.DataItem, "b") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="גודל">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "c")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxSize"
Text='<%# DataBinder.Eval(Container.DataItem, "c") %>'
runat="server" Height="22px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="מוצר">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "d")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxProduct"
Text='<%# DataBinder.Eval(Container.DataItem, "d") %>'
runat="server" Height="22px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update">
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
</Columns>
<EditItemStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:DataGrid>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblerror" runat="server" ForeColor="Maroon"></asp:Label>
</td>
</tr>
</table>
</asp:Content>
and finaly my CS code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Globalization;
using System.IO;
using System.Data;
using System.Data.OleDb;
public partial class EditTables : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!User.IsInRole("Admin"))
Server.Transfer("login.aspx");
if (!(Page.IsPostBack))
{
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
}
protected DataSet LoadMyData()
{
string sourceXml = Server.MapPath("~/xml/chores2.xml");
if (!(File.Exists(sourceXml)))
{
return null;
}
DataSet cachedDataSet = (DataSet)Session["table"];
if (!(cachedDataSet == null))
{
return cachedDataSet;
}
DataSet dataSet = new DataSet();
try
{
dataSet.ReadXml(sourceXml);
Session["table"] = dataSet;
}
catch (Exception e)
{
lblerror.Text = e.Message;
dataSet = null;
}
return dataSet;
}
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = Convert.ToInt32(e.Item.ItemIndex);
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
DataSet dataSet = LoadMyData();
int row = Convert.ToInt32(e.Item.ItemIndex);
dataSet.Tables[0].Rows[row].Delete();
dataSet.WriteXml(Server.MapPath("~/XML/chores2.xml"));
Session["table"] = null;
DataGrid1.EditItemIndex = -1;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
DataSet dataSet = LoadMyData();
int row = Convert.ToInt32(e.Item.ItemIndex);
int w = Convert.ToInt32(e.Item.Attributes);
TextBox txtBoxLabel = (TextBox)e.Item.FindControl("txtBoxLabel");
dataSet.Tables[0].Rows[row]["label"] = txtBoxLabel.Text;
TextBox txtBoxTitle = (TextBox)e.Item.FindControl("txtBoxTitle");
dataSet.Tables[0].Rows[row]["title"] = txtBoxTitle.Text;
TextBox txtBoxProduct = (TextBox)e.Item.FindControl("txtBoxProduct");
dataSet.Tables[0].Rows[3]["a"] = txtBoxProduct.Text;
TextBox txtBoxSize = (TextBox)e.Item.FindControl("txtBoxSize");
dataSet.Tables[0].Rows[3]["b"] = txtBoxSize.Text;
TextBox txtBoxPrice = (TextBox)e.Item.FindControl("txtBoxPrice");
dataSet.Tables[0].Rows[3]["c"] = txtBoxPrice.Text;
TextBox txtBoxAmount = (TextBox)e.Item.FindControl("txtBoxAmount");
dataSet.Tables[0].Rows[3]["d"] = txtBoxAmount.Text;
dataSet.WriteXml(Server.MapPath("~/XML/chores2.xml"));
Session["table"] = null;
DataGrid1.EditItemIndex = -1;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
}
The error i get starts in this line of code
dataSet.Tables[0].Rows[row]["a"] = txtBoxProduct.Text;
I've been told that this could be a problem in the number of Tables of the dataset, according to my XML file i should create 2 tables in DATASET.
any help please?
thank you.
|
|
|
|
|
|