Jump to content
vassili69

[Resolvido] ao inserir uma nova linha vem com os dados das linhas anteriores

Recommended Posts

vassili69

bas estou a tentar introduzir uns valores numa gridview a através de uma datatable.

o problema e que quando insero uma nova linha vem com os valores das linhas anteriores.

public DataTable InsertDiasGrid (int Emp)
{
string nome = String.Format("Select DescEmp from UserDetails Where NumEmp='" + Emp + "'");
SqlDataAdapter oda;
string query=String.Format("Select DiaMarcado from DiasMarcados Where NumEmp='"+Emp+"'");
connectSQL.Open();
SqlCommand cmd = new SqlCommand(query, connectSQL);
oda = new SqlDataAdapter(cmd);
oda.Fill(DiasMarcadosDT);
connectSQL.Close();
oda.Dispose();

string i1 = "-", i2 = "-", i3 = "-", i4 = "-", i5 = "-", i6 = "-", i7 = "-", i8 = "-", i9 = "-", i10 = "-", i11 = "-", i12 = "-";
string f1 = "-", f2 = "-", f3 = "-", f4 = "-", f5 = "-", f6 = "-", f7 = "-", f8 = "-", f9 = "-", f10 = "-", f11 = "-", f12 = "-";

DateTime dataNext = new DateTime();
DateTime Actualdata = new DateTime();


foreach (DataRow row in DiasMarcadosDT.Rows)
{
foreach (DataColumn column in DiasMarcadosDT.Columns)
{
DateTime data = Convert.ToDateTime(row[column].ToString());


if (data.Month.Equals(1))
{
if (i1 == "-")
{
i1 = data.Day.ToString();
dataNext = data;
}
else {
Actualdata = data;
if (DateDiffInDays(Actualdata, dataNext) == -1)
{
f1 = data.Day.ToString();
dataNext = Actualdata;
}
}
}
...

dtsource.Rows.Add(db.GetValue(nome), i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6, i7, f7, i8, f8, i9, f9, i10, f10, i11, f11, i12, f12);
return dtsource;
}

protected void Button1_Click(object sender, EventArgs e)
 {

	 objdatasource.InsertDiasGrid(3239);
	 grMergedCellExample.DataBind();
	 objdatasource.InsertDiasGrid(2658);
	 grMergedCellExample.DataBind();
 }

DataSource objdatasource = new DataSource();
	protected void Page_Load(object sender, EventArgs e)
	{
		grMergedCellExample.DataSource = objdatasource.MyDataTable();
		grMergedCellExample.DataBind();
	}

bas estou a tentar introduzir uns valores numa gridview a através de uma datatable.

o problema e que quando insero uma nova linha vem com os valores das linhas anteriores.

public DataTable InsertDiasGrid (int Emp)
{
string nome = String.Format("Select DescEmp from UserDetails Where NumEmp='" + Emp + "'");
SqlDataAdapter oda;
string query=String.Format("Select DiaMarcado from DiasMarcados Where NumEmp='"+Emp+"'");
connectSQL.Open();
SqlCommand cmd = new SqlCommand(query, connectSQL);
oda = new SqlDataAdapter(cmd);
oda.Fill(DiasMarcadosDT);
connectSQL.Close();
oda.Dispose();

string i1 = "-", i2 = "-", i3 = "-", i4 = "-", i5 = "-", i6 = "-", i7 = "-", i8 = "-", i9 = "-", i10 = "-", i11 = "-", i12 = "-";
string f1 = "-", f2 = "-", f3 = "-", f4 = "-", f5 = "-", f6 = "-", f7 = "-", f8 = "-", f9 = "-", f10 = "-", f11 = "-", f12 = "-";

DateTime dataNext = new DateTime();
DateTime Actualdata = new DateTime();


foreach (DataRow row in DiasMarcadosDT.Rows)
{
foreach (DataColumn column in DiasMarcadosDT.Columns)
{
DateTime data = Convert.ToDateTime(row[column].ToString());


if (data.Month.Equals(1))
{
if (i1 == "-")
{
i1 = data.Day.ToString();
dataNext = data;
}
else {
Actualdata = data;
if (DateDiffInDays(Actualdata, dataNext) == -1)
{
f1 = data.Day.ToString();
dataNext = Actualdata;
}
}
}
...

dtsource.Rows.Add(db.GetValue(nome), i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6, i7, f7, i8, f8, i9, f9, i10, f10, i11, f11, i12, f12);
return dtsource;
}

protected void Button1_Click(object sender, EventArgs e)
 {

	 objdatasource.InsertDiasGrid(3239);
	 grMergedCellExample.DataBind();
	 objdatasource.InsertDiasGrid(2658);
	 grMergedCellExample.DataBind();
 }

DataSource objdatasource = new DataSource();
	protected void Page_Load(object sender, EventArgs e)
	{
		grMergedCellExample.DataSource = objdatasource.MyDataTable();
		grMergedCellExample.DataBind();
	}

já descobri lol. tinha que limpar a datatable temporaria no fim.

DiasMarcadosDT.Clear();

Edited by vassili69

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.