Groups | Blog | Home
all groups > asp.net datagrid control > december 2006 >

asp.net datagrid control : GridView Update?



sebastian.buschdorf
12/12/2006 12:00:00 AM
Hello,

I'm new in programming with ASP.NET 2.0 and I have a problem with the
updating of the Grid View!
I have one GridView with a connection to a database, three textboxes and a
[quoted text, click to view]
down to the database, after clicking the button! That's worked, but the
GridView don't show the Values after that! When I click
the button the second time, then the GridView shows the Values, but he had
then two records in the database of that value!

Here is my Code:

protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString =
"server=buero3;Trusted_Connection=yes;database=Personal";
SqlConnection conn = new SqlConnection(ConnectionString);

conn.Open();

string Sql = "SELECT * FROM Mitarbeiter";

SqlCommand cmd = new SqlCommand(Sql, conn);
SqlDataReader reader = cmd.ExecuteReader();

myGridView.DataSource = reader;

DataBind();

myGridView.GridLines = GridLines.Both;

conn.Close();

lblDatum.Text = DateTime.Now.ToString();

txtName.Focus();

}
protected void btnAnmelden_Click(object sender, EventArgs e)
{
string ConnectionString =
"server=buero3;Trusted_Connection=yes;database=Personal";
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Mitarbeiter (Name, Vorname,
Abteilung) VALUES (@valName, @valVorname, @valAbteilung)";
cmd.Parameters.Add("@valName", SqlDbType.VarChar, 50).Value =
txtName.Text;
cmd.Parameters.Add("@valVorname", SqlDbType.VarChar, 50).Value =
txtVorname.Text;
cmd.Parameters.Add("@valAbteilung", SqlDbType.VarChar, 50).Value =
txtAbteilung.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();


Regards,
Sebastian

P.S. Sry for my bad English! *g

sebastian.buschdorf
12/12/2006 4:39:35 PM
I've got it! :-)


"sebastian.buschdorf" <seb1astian.bus2chdorf@hn3c-daten4echnik.de> schrieb
im Newsbeitrag news:elltlh$q92$1@online.de...
[quoted text, click to view]

AddThis Social Bookmark Button