View Full Version : بازیابی اطلاعات از بانک به آبجکت
mirshakkeh
یک شنبه 13 اردیبهشت 1388, 08:17 صبح
با سلام
من 3 تا جدول دارم که از طریق کلید خارجی با هم در ارتباط اند حال چه طور می تونم اطلاعات رو (مثلا اطلاعات یک نفر)از داخل این جدول ها به تعدادی تکس باکس یا متغیر منتقل کنم.
kiosksoft
یک شنبه 13 اردیبهشت 1388, 08:54 صبح
دوست عزیزابتدا داده ها به DataTable بایند کنید سپس مقادیر اون رو میتونید دریافت و نمایش بدهید.
publicDataTable GetDTWithSql(string sql)
{
SqlConnection myConnection = newSqlConnection(GetSqlConnection("ConnStr"));
SqlCommand cmd = newSqlCommand(sql, myConnection);
cmd.CommandType = CommandType.Text;
//-------------------------------------------------------------------
SqlDataAdapter myCommand = newSqlDataAdapter(cmd);
myCommand.SelectCommand = cmd;
DataTable DT = newDataTable();
myCommand.Fill(DT);
myConnection.Open();
myConnection.Close();
return DT;
}
DT = dbClass.GetDTWithSql("select * from okTbl where(id=1)");
txtName.Text = DT.Rows[0]["Name"].ToString();
txtLastName.Text = DT.Rows[0]["LastName"].ToString();
txtPersonelCode.Text = DT.Rows[0]["PersonelCode"].ToString();
drpPartID.SelectedValue = DT.Rows[0]["PartID"].ToString();
برای توسعه کارتون از این تاپیک ها میتونید استفاده کنید.
http://barnamenevis.org/forum/showthread.php?t=126978
http://barnamenevis.org/forum/showthread.php?t=127376
NewFoxStudent
یک شنبه 13 اردیبهشت 1388, 09:53 صبح
میتونید از کلاس SqlDataReader هم استفاده کنید
NewFoxStudent
یک شنبه 13 اردیبهشت 1388, 09:57 صبح
SqlConnection sqlConnection = new SqlConnection(ConnectionString);
SqlCommand sqlCommand = new SqlCommand("Select FieldList From TableName Where whereCondition",sqlConnection);
sqlConnection.Open();
SqlDataReder sqlReader = sqlCommane.ExecuteReader();
if(sqlReader.Read())
{
textbox1.text = sqlReader["FieldName"].ToString();
.
.
.
}
sqlReader.Close();
sqlConnection.Close();
captain_black81
یک شنبه 13 اردیبهشت 1388, 11:17 صبح
string command = "select count(period) from [mojudi] where residintCode=" + cashintCode + ;
//Connecting to SQL-Kian-Anbar
SqlConnection cnm = new SqlConnection();
general g = new general();
cnm.ConnectionString = "connectionString";
//Stored Procedure Define
SqlCommand cm = new SqlCommand();
cm.Connection = cnm;
cm.CommandText = command;
cm.CommandType = CommandType.Text;
object s;
cnm.Open();
s = cm.ExecuteScalar();
cnm.Close();
string ret = Convert.ToString(s);
return ret;
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.