Hi all,
I'm trying to create a method Load that will call a stored procedure,the source code has some problems,really need some guidance still new in C#
Ok here's the code now with some minor adjustments rather than just getting one data,i'm planning on retrieving all the parameter just by getting the DateID,not sure if its the correct way...
The error is 'no overload for method data'
Since i'm new in C# can anyone suggest to me any good way to read error and fix it.
class Program
{
private int _dateID;
private int _dateTypeID;
private DateTime _date;
private string _name;
private string _notes;
public Program(int dateID) {
_dateID = dateID;
}
public Program(int datetypeID,DateTime date,string name,string notes){
_dateTypeID = datetypeID;
_date = date;
_name = name;
_notes = notes;
}
public int dateID { get; set; }
public int dateTypeID { get; set; }
public DateTime date { get; set; }
public string name { get; set; }
public string notes { get; set; }
//suppose to retrieve all the data from DateID and show all
// the attributes in table Date
//Am i doing this the right way?
public void LoadData()
{
SqlConnection conn = new SqlConnection("SOMEDATABASE");
SqlCommand command = new SqlCommand("p_Date_sel", conn);
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@DateID";
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "p_Date_sel";
command.Parameters.Add(parameter);
conn.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["Dates"]); //error on this line
}
conn.Close();
}
01 public static void Main(string[] args)
02 {
03 /*No 56 is already in the table with all the parameters,
04 i cant even show the dateID*/
05 Program p = new Program(56);
06 p.LoadData(56);
07
08 Console.WriteLine("DateID = " + "" + p.dateID);
09 Console.WriteLine("DateTypeID = " + "" + p.dateTypeID);
10 Console.WriteLine("Date = " + "" + p.date);
11 Console.WriteLine("Name = " + "" + p.name);
12 Console.WriteLine("Notes = " + "" + p.notes);
13
14 Console.ReadLine();
15 }