title image


Smiley Re: Kopieren von DataSet
Daten einbinden:

public void SW()

{

try

{

string strConn =(string)Session["strConn"];

string mySQ = "SELECT SWArtName FROM SWArt";

SqlConnection conn = new SqlConnection(strConn);

SqlCommand cmd = new SqlCommand(mySQ, conn);

try

{

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable ds = new DataTable("SWT");

da.Fill(ds);

DataGrid1.DataSource = ds;

DataGrid1.DataMember = "SWT";

DataGrid1.DataBind();

Session["SWT"] = ds;

DataView dv = new DataView(ds);

}

catch(Exception e){MeldungenLabel.Text = e.ToString();}

}

catch(Exception e){MeldungenLabel.Text = e.ToString();}

}



Daten Editiren und zurück übertragen:

private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

Session["TBox"] = e.Item.Cells[1].Text;

GetTBox();

DataGrid1.EditItemIndex = e.Item.ItemIndex;

SW();

}



public void DataGrid1_Cancel(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

DataGrid1.EditItemIndex = -1;

SW();

}



private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

int I = (int)Session["I"];

string SWN = ((TextBox)e.Item.Cells[1].Controls[0]).Text;

string S = SWArtBox.Text;

string strConn =(string)Session["strConn"];

SqlConnection cn = new SqlConnection(strConn);

cn.Open();

try

{

SqlCommand cmd = cn.CreateCommand();

cmd.CommandText = "UPDATE SWArt SET SWArtName = @SWN WHERE SWArtID = @I";

cmd.Parameters.Add("@SWN", SWN);

cmd.Parameters.Add("@I", I);

cmd.ExecuteNonQuery();

}

catch(Exception a){MeldungenLabel.Text = a.ToString();}

cn.Close();

DataGrid1.EditItemIndex = -1;

SW();

}

public void GetTBox()

{

string S = (string)Session["TBox"];

string strConn =(string)Session["strConn"];

string mySelectQuery = "SELECT SWArtID FROM SWArt Where SWArtName like UPPER(@S)";

SqlConnection myConnection = new SqlConnection(strConn);

SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);

myCommand.Parameters.Add("@S", S);

myConnection.Open();

try

{

using (SqlDataReader myReader = myCommand.ExecuteReader())

{

while (myReader.Read())

{

Session["I"] = myReader.GetInt32(0);

}

myReader.Close();

}

}

catch(Exception a){MeldungenLabel.Text = a.ToString();}

myConnection.Close();

}

Ich hoffe das Hilt dir

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: