با سلام
دوستان من بین 3 جدولم join بستم حالا این join من اومده تعداد سطرای malirecieve*cardtocard کرده میاره نشون میده و این کار باعث شده کلی سطر تکراری من داشته یاشم تو گزارشم
این دستورم:
SqlConnection connect = new SqlConnection();
connect.ConnectionString = Ajans.Properties.Settings.Default.Connection.ToStr ing();
string conditions = "1=1";
if (checkBox1.Checked == true)
{
conditions += "and MP.namebank='" + NameBank.Text + "' ";
}
else
{
checkBox1.Checked = false;
}
if (checkBox4.Checked == true)
{
conditions += "and SP.dateharekat='" + DateHarekat.Value.FarsiSelectedDate + "' ";
}
else
{
checkBox4.Checked = false;
}
if (checkBox5.Checked == true)
{
conditions += "and MR.Nametor='" + nametor.Text + "' ";
}
else
{
checkBox5.Checked = false;
}
if (checkBox2.Checked == true)
{
conditions += "and MR.DateRecieve between '" + From.Value.FarsiSelectedDate + "' and '" + To.Value.FarsiSelectedDate + "' ";
}
else
{
checkBox2.Checked = false;
}
//-------------------پرداختی ها
string conditions1 = "1=1";
if (checkBox1.Checked == true)
{
conditions1 += "and CardToCardPeyment.NameBank='" + NameBank.Text + "' ";
}
else
{
checkBox1.Checked = false;
}
if (checkBox4.Checked == true)
{
conditions1 += "and customer.dateharekat='" + DateHarekat.Value.FarsiSelectedDate + "' ";
}
else
{
checkBox4.Checked = false;
}
if (checkBox5.Checked == true)
{
conditions1 += "and MaliPeyment.Nametor='" + nametor.Text + "'";
}
else
{
checkBox5.Checked = false;
}
if (checkBox2.Checked == true)
{
conditions1 += "and MaliPeyment.DateRecieve between'" + From.Value.FarsiSelectedDate + "' and '" + To.Value.FarsiSelectedDate + "'";
}
else
{
checkBox2.Checked = false;
}
if (Type.SelectedIndex == 0)
{
DG.Visible = true;
pardakht.Visible = false;
try
{
connect.Open();
// SqlDataAdapter saeed = new SqlDataAdapter(@"select MaliRecieve.shgh as [ش قرارداد],MaliRecieve.FamilyM as [نام مسافر],MaliRecieve.Nametor as [نام تور],customer.dateharekat as [تاریخ حرکت],customer.Count as تعداد,CardtoCard.Malirecieve as مبلغ ,MaliRecieve.TypeRecieve as [نوع دریافت], CardtoCard.ShPeygiri as [ش پیگیری],MaliRecieve.tarafhesab as [طرف حساب] From MaliRecieve inner join customer on malirecieve.shgh=customer.shgh inner join cardtocard on cardtocard.shgh=malirecieve.shgh where Customer.typePassenger='true' And " + conditions, connect);
SqlDataAdapter saeed = new SqlDataAdapter(@"select MR.ShGh AS شرح
,MR.FamilyM AS [نام مسافر]
,SP.dateharekat AS [تاریخ حرکت]
,MR.DateRecieve as [تاریخ دریافت]
,SP.count AS تعداد
,MP.Malirecieve AS مبلغ
,MR.TypeRecieve AS [نوع دریافتی]
,MP.ShPeygiri AS [ش پیگیری]
,MR.Nametor AS [نام تور]
,MR.tarafhesab AS [طرف حساب]
From
malirecieve MR Full Outer Join cardtocard MP
ON
MR.ShGh = MP.ShGh Full Outer Join customer SP ON MR.Shgh=SP.Shgh where SP.typePassenger='true' And " + conditions, connect);
DataTable t = new DataTable(); saeed.Fill(t);
DG.DataSource = t;
DG.RetrieveStructure();
DG.RootTable.Columns[5].FormatString = "#,#";
}
catch (Exception x)
{
MessageBox.Show(x.Message.ToString());
}
finally
{
connect.Close();
}
}
else
{
if (Type.SelectedIndex == 1)
{
DG.Visible = false;
pardakht.Visible = true;
try
{
connect.Open();
SqlDataAdapter insert = new SqlDataAdapter(@"select MaliPeyment.shgh as [ش قرارداد],MaliPeyment.FamilyM as [نام مسافر],MaliPeyment.Nametor as [نام تور],customer.dateharekat as [تاریخ حرکت],customer.Count as تعداد,CardToCardPeyment.Malirecieve as مبلغ ,MaliPeyment.TypeRecieve as [نوع پرداخت],CardToCardPeyment.ShPeygiri as [ش پیگیری] From MaliPeyment Full Outer Join CardToCardPeyment on MaliPeyment.shgh=CardToCardPeyment.shgh Full Outer Join customer on MaliPeyment.shgh=customer.shgh where Customer.typePassenger='true' And " + conditions1, connect);
DataTable t = new DataTable(); insert.Fill(t);
pardakht.DataSource = t;
pardakht.RetrieveStructure();
pardakht.RootTable.Columns[5].FormatString = "#,#";
}
catch (Exception x)
{
MessageBox.Show(x.Message.ToString());
}
finally
{
connect.Close();
}
}
else
{
}
}
دوستان من بدجوری نیاز دارم به حل این مشکل.
دستور سلکت من طوری هست که میار از شروط ترکیبی استفاده میکنه اگه تو دستورم دقت کنین متوجه میشین به خاطر همین هم نمی تونم از group by استفاده کنم چرا که دستور سلکت من با +condition تموم میشه
لطفا کمکم کنین