Forum

C# Constructor Soru...
 
Bildirimler
Hepsini Temizle

C# Constructor Sorunu

6 Yazılar
2 Üyeler
0 Likes
1,017 Görüntüleme
 FCO
(@fco)
Gönderiler: 28
Trusted Member
Konu başlatıcı
 

Merhabalar ekteki resimde gördüğünüz üzere tanımladığım Constructor'da "Method must have a return type" hatası veriyor. Yardımcı olursanız sevinirim. Gereken başka materyal varsa yazarsanız gönderebilirim.

 
Gönderildi : 14/01/2011 12:36

(@ismailadar)
Gönderiler: 134
Estimable Member
 

Merhabalar,


Clasınızı adı nedşr? Class ıda paylaşabilirmisiniz?

 
Gönderildi : 14/01/2011 12:44

 FCO
(@fco)
Gönderiler: 28
Trusted Member
Konu başlatıcı
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Collections;

namespace Loltube.Classes
{
public class Database
{
#region Değişkenler

private int _ID;
private string _Adi;
private int _OgrNo;
private string _Sinif;
private string _Tarih;

#endregion

#region Propertyler

public int ID
{
get { return _ID; }
set { _ID = value; }
}

public string Adi
{
get { return _Adi; }
set { _Adi = value; }
}

public int OgrNo
{
get { return _OgrNo; }
set { _OgrNo = value; }
}

public string Sinif
{
get { return _Sinif; }
set { _Sinif = value; }
}

public string Tarih
{
get { return _Tarih; }
set { _Tarih = value; }
}

#endregion

#region Boş Constructor

public void Ogrenci(int ID, string Adi, int OgrNo, string Sinif, string Tarih)
{

}

#endregion

#region ID'ye göre Constructor

public Ogrenci(int ID, string Adi, int OgrNo, string Sinif, string Tarih)
{

this._ID=ID;
this._Adi=Adi;
this._OgrNo=OgrNo;
this._Sinif=Sinif;
this._Tarih=Tarih;

}

#endregion

#region ID'siz Constructor

public Ogrenci(string Adi, int OgrNo, string Sinif, string Tarih)
{

this._Adi = Adi;
this._OgrNo = OgrNo;
this._Sinif = Sinif;
this._Tarih = Tarih;

}

#endregion

#region Ezme

public override string ToString()
{
return this._Adi;
}

#endregion

#region Metodlar

public static void Kayit(Database Ogrencim)
{

OleDbConnection cn = new OleDbConnection(Classes.DbCore.Connection);

OleDbCommand com = new OleDbCommand("insert into Ogrenci(ID,Adi,OgrNo,Sinif,Tarih) values(@ID,@Adi,@OgrNo,@Sinif,@Tarih)",cn);

com.Parameters.AddWithValue("@ID",Ogrencim.ID);
com.Parameters.AddWithValue("@Adi",Ogrencim.Adi);
com.Parameters.AddWithValue("@OgrNo",Ogrencim.OgrNo);
com.Parameters.AddWithValue("Sinif",Ogrencim.Sinif);
com.Parameters.AddWithValue("Tarih",Ogrencim.Tarih);

cn.Open();
com.ExecuteNonQuery();
cn.Close();

}

public static void Silme(ComboBox Kombom)
{
OleDbConnection cn = new OleDbConnection(Classes.DbCore.Connection);
OleDbCommand com = new OleDbCommand("Delete From Ogrenci Where Id=@ID", cn);

int ID = int.Parse(Kombom.SelectedValue.ToString());

com.Parameters.AddWithValue("@ID",ID);

cn.Open();
com.ExecuteNonQuery();
cn.Close();

}

public static void Temizle(ComboBox ID, TextBox Ad, TextBox OgrenciNo, TextBox Sinifi, TextBox Tarihi)
{

ID.ResetText();
Ad.ResetText();
OgrenciNo.ResetText();
Sinifi.ResetText();
Tarihi.ResetText();

}

public static void ComboBoxDoldur(ComboBox Kombom)
{
OleDbConnection cn = new OleDbConnection(Classes.DbCore.Connection);
OleDbDataAdapter da = new OleDbDataAdapter("Select ID, Adi From Ogrenci",cn);
DataTable dt = new DataTable();
da.Fill(dt);

Kombom.DisplayMember="Adi";
Kombom.ValueMember="ID";
Kombom.DataSource = dt;
}

public static void ComboBoxSelectedIndexChangedMethod(ComboBox Kombom, TextBox Ad, TextBox OgrenciNo, TextBox Sinifi, TextBox Tarihi)
{
if (Kombom.SelectedIndex==-1)
{

Kombom.ResetText();
Ad.ResetText();
OgrenciNo.ResetText();
Sinifi.ResetText();
Tarihi.ResetText();

}
else
{

OleDbConnection cn = new OleDbConnection(Classes.DbCore.Connection);
OleDbCommand com = new OleDbCommand("Select Adi,OgrNo,Sinifi,Tarih from Ogrenci Where ID=@ID", cn);
com.Parameters.AddWithValue("@ID", Kombom.SelectedValue);

if (com.Connection.State == ConnectionState.Closed)
{
com.Connection.Open();
}

OleDbDataReader dr = com.ExecuteReader();

if (dr.HasRows)
{
while (dr.Read())
{

Ad.Text=dr["Adi"].ToString();
OgrenciNo.Text=dr["OgrNo"].ToString();
Sinifi.Text=dr["Sinifi"].ToString();
Tarihi.Text=dr["Tarih"].ToString();

}
}
dr.Close();
cn.Close();
}
}

#endregion
}
}

 
Gönderildi : 14/01/2011 13:50

(@ismailadar)
Gönderiler: 134
Estimable Member
 

Merhabalar,


Constructor için en onemli sart class adı ile aynı olmasıdır.Construct adınızı class adı ile değiştirin yani constructor ın adı da Database olmalıdır

 
Gönderildi : 14/01/2011 15:04

 FCO
(@fco)
Gönderiler: 28
Trusted Member
Konu başlatıcı
 

Teşekkürler. Bir anda çıkmış aklımdan. Sağolun

 
Gönderildi : 14/01/2011 16:26

(@ismailadar)
Gönderiler: 134
Estimable Member
 

onemli değil kolay gelsin

 
Gönderildi : 14/01/2011 16:46

Paylaş: