4 Replies - 22565 Views - Last Post: 19 May 2009 - 10:51 PM Rate Topic: -----

#1 grishma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 09

Type or namespace definition, or end-of-file expected, } expected

Posted 19 May 2009 - 09:33 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using dao;
using RKLib.ExportData;



namespace Get_SABA_Details
{
	class Program
	{
		static void Main(string[] args)
		{
		   private DataTable getData()
		{
			DataSet ds = null;
			try
			{
				object[] objPara = getParaVal();
				if (objPara.Length > 0)
				{

					DBAccess _oDA = new DBAccess();
					DbConnection dbCon = _oDA.InitConnection(ConnectTo.SQLCon);
					DbCommand dbCom = _oDA.InitDbCommand(dbCon, "dbo.ZSP_GET_SABA_DETAIL");
					ds = _oDA.getData(dbCom);
					if (ds.Tables[0].Rows.Count == 0)
						lblMessage.Text = "No Records found!";
				}
			}
			catch (Exception ex)
			{
				throw ex;

			}
			return ds.Tables[0];
		}
	}
		}
	}



pls help how to get rid of this error??????

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

This post has been edited by PsychoCoder: 19 May 2009 - 10:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Type or namespace definition, or end-of-file expected, } expected

#2 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: Type or namespace definition, or end-of-file expected, } expected

Posted 19 May 2009 - 09:47 PM

You can't nest methods like that unless you change your getData() method into a delegate. If you don't want to play with delegates, move the getData() method outside of the Main() method.
Was This Post Helpful? 0
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Type or namespace definition, or end-of-file expected, } expected

Posted 19 May 2009 - 10:03 PM

If you do move it outside in that file I believe you also have to make it static.
Was This Post Helpful? 0
  • +
  • -

#4 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: Type or namespace definition, or end-of-file expected, } expected

Posted 19 May 2009 - 10:42 PM

View PostSixOfEleven, on 19 May, 2009 - 09:03 PM, said:

If you do move it outside in that file I believe you also have to make it static.


Sorry, you're right, unless for some reason grishma wants to instantiate the Program class.
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Type or namespace definition, or end-of-file expected, } expected

Posted 19 May 2009 - 10:51 PM

You have been given all the answers, move getData() outside of Main() and make it static, like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using dao;
using RKLib.ExportData;



namespace Get_SABA_Details
{
	class Program
	{
		static void Main(string[] args)
		{

		}

		private static DataTable getData()
		{
			DataSet ds = null;
			try
			{
				object[] objPara = getParaVal();
				if (objPara.Length > 0)
				{

					DBAccess _oDA = new DBAccess();
					DbConnection dbCon = _oDA.InitConnection(ConnectTo.SQLCon);
					DbCommand dbCom = _oDA.InitDbCommand(dbCon, "dbo.ZSP_GET_SABA_DETAIL");
					ds = _oDA.getData(dbCom);
					if (ds.Tables[0].Rows.Count == 0)
						lblMessage.Text = "No Records found!";
				}
			}
			catch (Exception ex)
			{
				throw ex;

			}
			return ds.Tables[0];
		}
	}
}


Was This Post Helpful? 1

Page 1 of 1