Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've created a database in MS-SQL and used it in my application. But sometimes it doesn't responds randomly and throws an exception System.Data.DataRowView' does not contain a property with the name 'service_name' while the column is in my table. Later on I've been dropped that DB and again created a new DB with new name but the problem remain persist. But this issue has not been occurred with the other existing DBs.

I'm using this connection string:

<add name="testCon" connectionString="Data Source=Comp1;Initial Catalog=TestDB;Persist Security Info=True;User ID=test;Password=test;" providerName="System.Data.SqlClient"/>

and using this command on code behind

select t.id, t.service_name from dbo.[Table_Name] t

By using this command I'm filling a Drop Down-List and above problem occurs.

This works properly on SQL but occurred at front-end.

Here is the sample code:

SqlDataAdapter da = new SqlDataAdapter("select t.id, t.service_name from   dbo.[Table_Name] t", testCon);
DataTable dtt = new DataTable();
da.Fill(dtt);
if (dtt.Rows.Count > 0)
{
  ddl1_sel.DataSource = dtt.DefaultView;
  ddl1_sel.DataTextField = "service_name";
  ddl1_sel.DataValueField = "id";
  ddl1_sel.DataBind();
  ddl1_sel.Items.Insert(0, new ListItem("Select Service", "0"));
}

and the exact error is:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'service_name'. Object reference not set to an instance of an object.
share|improve this question
1  
ASAP? Really? This isn't a help desk... –  nojak Aug 12 '12 at 3:23
    
Interesting enough SQL Server does not contain System.Data.DataRowView, which is something that is more related to - the (bad) .NET way to acces databases (DataSet, DataTable). A such, it is quite likely that this is not at all a MS SQL issue but simply bad code. Provide a full minimal example please. –  TomTom Aug 12 '12 at 5:34
    
@TomTom:I've added the sample code with the Question.. I've posted the question on msdn at social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/thread/… and at asp.net forum at forums.asp.net/p/1832022/5101101.aspx/… but no one have the proper solution. –  Prashant Gupta Aug 13 '12 at 6:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.