473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

quick issue

Hey guys - I seriously need some help. got an assignment due tomorrow and
I'm totally stuck. Here's my comment and and I need help with the code to
update the database as well as delete items. Any help is appreciated.

thanks

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Configuration;

using System.Data.SqlClient;

using System.Data.SqlTypes;

namespace _2870assign2

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

public string strConn = ConfigurationSettings.AppSettings["ConnStr"];

protected System.Web.UI.WebControls.DataGrid DataGrid1;

protected System.Web.UI.WebControls.Label Label1;

public string sql = ConfigurationSettings.AppSettings["SQLStrings"];

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.Label Label3;

protected System.Web.UI.WebControls.Label Label4;

protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

SqlConnection conn = new SqlConnection(strConn);

SqlDataAdapter da = new SqlDataAdapter(sql, conn);

DataSet ds = new DataSet();

da.Fill(ds, "Users");

DataGrid1.DataSource = ds;

DataGrid1.DataBind();

try

{

conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn);

SqlDataReader reader = cmd.ExecuteReader();

DataGrid1.DataBind();

Label1.Text = "Opened Connection to " + conn.Database;

Label1.Text = "SQL server version " + conn.ServerVersion;

}

catch(Exception ex)

{

Label1.Text = "Connection failed " + ex.Message;

}

finally

{

conn.Close();

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.DataGrid1.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_CancelC
ommand);

this.DataGrid1.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_EditCom
mand_1);

this.DataGrid1.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_UpdateC
ommand);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

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

{

DataGrid1.EditItemIndex = e.Item.ItemIndex;

DataGrid1.DataBind();

}

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

{

DataGrid1.EditItemIndex = -1;

DataGrid1.DataBind();

}

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

{

string ID = DataGrid1.DataKeyField.ToString();
///string username = ((TextBox)e.Item.Cells[1].Controls[0]).Text;

//// string password = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
/// Label2.Text = username;

/// Label3.Text = password;

Label4.Text = ID.ToString();

DataGrid1.EditItemIndex = e.Item.ItemIndex;

DataGrid1.DataBind();

}


}

}
Nov 16 '05 #1
8 1064
What's the problem?

You cannot just post a piece of code and expect that people are going to:
a) try to figure out what you are trying to do
b) try to figure out what is going wrong
c) fix your problem

You need to give more context. Otherwise nobody's going to help you.
Also, don't post whole files like this, only post small pieces of code that
are relevant to your problem.

Bruno.

"troy" <tr**@ttech.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hey guys - I seriously need some help. got an assignment due tomorrow and
I'm totally stuck. Here's my comment and and I need help with the code to
update the database as well as delete items. Any help is appreciated.

thanks

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Configuration;

using System.Data.SqlClient;

using System.Data.SqlTypes;

namespace _2870assign2

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

public string strConn = ConfigurationSettings.AppSettings["ConnStr"];

protected System.Web.UI.WebControls.DataGrid DataGrid1;

protected System.Web.UI.WebControls.Label Label1;

public string sql = ConfigurationSettings.AppSettings["SQLStrings"];

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.Label Label3;

protected System.Web.UI.WebControls.Label Label4;

protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

SqlConnection conn = new SqlConnection(strConn);

SqlDataAdapter da = new SqlDataAdapter(sql, conn);

DataSet ds = new DataSet();

da.Fill(ds, "Users");

DataGrid1.DataSource = ds;

DataGrid1.DataBind();

try

{

conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn);

SqlDataReader reader = cmd.ExecuteReader();

DataGrid1.DataBind();

Label1.Text = "Opened Connection to " + conn.Database;

Label1.Text = "SQL server version " + conn.ServerVersion;

}

catch(Exception ex)

{

Label1.Text = "Connection failed " + ex.Message;

}

finally

{

conn.Close();

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.DataGrid1.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_CancelC ommand);

this.DataGrid1.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_EditCom mand_1);

this.DataGrid1.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_UpdateC ommand);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

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

{

DataGrid1.EditItemIndex = e.Item.ItemIndex;

DataGrid1.DataBind();

}

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

{

DataGrid1.EditItemIndex = -1;

DataGrid1.DataBind();

}

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

{

string ID = DataGrid1.DataKeyField.ToString();
///string username = ((TextBox)e.Item.Cells[1].Controls[0]).Text;

//// string password = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
/// Label2.Text = username;

/// Label3.Text = password;

Label4.Text = ID.ToString();

DataGrid1.EditItemIndex = e.Item.ItemIndex;

DataGrid1.DataBind();

}


}

}

Nov 16 '05 #2
Bruno Jouhier [MVP] <bj******@club-internet.fr> wrote:
What's the problem?

You cannot just post a piece of code and expect that people are going to:
a) try to figure out what you are trying to do
b) try to figure out what is going wrong
c) fix your problem
Agreed.
You need to give more context. Otherwise nobody's going to help you.
Also, don't post whole files like this, only post small pieces of code that
are relevant to your problem.


While I agree that posting huge chunks of code isn't nice (especially
when OE has mangled it so there's an empty line between each line of
code), I have a strong personal preference for whole files. Whole files
can be cut and paste, and then compiled with no further effort.
Snippets take more time. I just like the whole files to still be small
:)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
sorry - didnt mean to offend anybody.

The issue is that I dont know how to update the fields changed in the
datagrid when a user clicks on the edit function. I tried using the
following logic but it gives me an castring error:

// Gets the value the TextBox control in the third column
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
username = tb.Text;
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Bruno Jouhier [MVP] <bj******@club-internet.fr> wrote:
What's the problem?

You cannot just post a piece of code and expect that people are going to: a) try to figure out what you are trying to do
b) try to figure out what is going wrong
c) fix your problem


Agreed.
You need to give more context. Otherwise nobody's going to help you.
Also, don't post whole files like this, only post small pieces of code that are relevant to your problem.


While I agree that posting huge chunks of code isn't nice (especially
when OE has mangled it so there's an empty line between each line of
code), I have a strong personal preference for whole files. Whole files
can be cut and paste, and then compiled with no further effort.
Snippets take more time. I just like the whole files to still be small
:)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
> While I agree that posting huge chunks of code isn't nice (especially
when OE has mangled it so there's an empty line between each line of
code), I have a strong personal preference for whole files. Whole files
can be cut and paste, and then compiled with no further effort.
Snippets take more time. I just like the whole files to still be small
:)


Yes, but the first thing to do is to describe the problem, with snipplets of
a few lines, because we can often figure out what's wrong by just looking at
these few lines of code. The whole file can be posted afterwards, in a
reply, if the problem is not straightforward. At least, I prefer it this
way.

This style of posting ("I have an urgent assignment, please debug my
program") is just not acceptable.

Bruno.
Nov 16 '05 #5
Jon Skeet [C# MVP] wrote:

[...]
You need to give more context. Otherwise nobody's going to help you.
Also, don't post whole files like this, only post small pieces of code that
are relevant to your problem.


While I agree that posting huge chunks of code isn't nice (especially
when OE has mangled it so there's an empty line between each line of
code), I have a strong personal preference for whole files. Whole files
can be cut and paste, and then compiled with no further effort.
Snippets take more time. I just like the whole files to still be small
:)


Also, there are special sites for posting source code to ( e.g.
http://sourcepost.sytes.net/ ), where one can post source and have it
syntax-highlighted, etc.

Example posting: http://sourcepost.sytes.net/sourcevi...ource_id=14487
Nov 16 '05 #6
troy <tr**@ttech.com> wrote:
sorry - didnt mean to offend anybody.

The issue is that I dont know how to update the fields changed in the
datagrid when a user clicks on the edit function. I tried using the
following logic but it gives me an castring error:

// Gets the value the TextBox control in the third column
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
username = tb.Text;


What casting error did you get? Have you tried debugging to find out
what the actual type is?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
Did you try e.Item.Cells[1].Text ?

Bruno.

"troy" <tr**@ttech.com> a écrit dans le message de
news:%2******************@TK2MSFTNGP10.phx.gbl...
sorry - didnt mean to offend anybody.

The issue is that I dont know how to update the fields changed in the
datagrid when a user clicks on the edit function. I tried using the
following logic but it gives me an castring error:

// Gets the value the TextBox control in the third column
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
username = tb.Text;
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Bruno Jouhier [MVP] <bj******@club-internet.fr> wrote:
What's the problem?

You cannot just post a piece of code and expect that people are going to: a) try to figure out what you are trying to do
b) try to figure out what is going wrong
c) fix your problem


Agreed.
You need to give more context. Otherwise nobody's going to help you.
Also, don't post whole files like this, only post small pieces of code that are relevant to your problem.


While I agree that posting huge chunks of code isn't nice (especially
when OE has mangled it so there's an empty line between each line of
code), I have a strong personal preference for whole files. Whole files
can be cut and paste, and then compiled with no further effort.
Snippets take more time. I just like the whole files to still be small
:)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #8
Thanks for the responses guys but I got it figured out.
"Bruno Jouhier [MVP]" <bj******@club-internet.fr> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
Did you try e.Item.Cells[1].Text ?

Bruno.

"troy" <tr**@ttech.com> a écrit dans le message de
news:%2******************@TK2MSFTNGP10.phx.gbl...
sorry - didnt mean to offend anybody.

The issue is that I dont know how to update the fields changed in the
datagrid when a user clicks on the edit function. I tried using the
following logic but it gives me an castring error:

// Gets the value the TextBox control in the third column
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
username = tb.Text;
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Bruno Jouhier [MVP] <bj******@club-internet.fr> wrote:
> What's the problem?
>
> You cannot just post a piece of code and expect that people are going
to:
> a) try to figure out what you are trying to do
> b) try to figure out what is going wrong
> c) fix your problem

Agreed.

> You need to give more context. Otherwise nobody's going to help you.
> Also, don't post whole files like this, only post small pieces of
code that
> are relevant to your problem.

While I agree that posting huge chunks of code isn't nice (especially
when OE has mangled it so there's an empty line between each line of
code), I have a strong personal preference for whole files. Whole

files can be cut and paste, and then compiled with no further effort.
Snippets take more time. I just like the whole files to still be small
:)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tom | last post by:
I have made in the past a bunch of VB apps to test hardware. They work and some call functions written in C++ (dll calls). I need to make a quick, dirty and cheap console app to access a PCI...
1
by: jack | last post by:
I pulled this script out of a larger one to test, and I can't figure it out. If I keep this script in the same directory as the files I want to read, it works fine, but if I move the script out of...
30
by: Christopher Benson-Manica | last post by:
Given the following: char s="Hello, world\n!"; Are all the following guaranteed to produce the same output? printf( "%s", s ); fprintf( stdout, "%s", s ); fwrite( s, sizeof(char),...
12
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty...
7
by: signo | last post by:
Hello to everybody, I'm trying to make a link that closes the browser: <a href="javascript:window.close()">CLOSE</a> It works with IE6 but not with Mozilla and Netscape. Does anybody knows...
5
by: David Thielen | last post by:
Hi; Almost all of the Quick Starts show the code in the .aspx file inside a <script> instead of in a seperate .aspx.cs file. My instinct is that the code should be in a seperate file to keep the...
13
by: alvinwoon | last post by:
URL: http://events.unl.edu/ Description: i coded a quick and dirty key navigation for the calendar. if you press left arrow on your keyboard, it will navigate to the previous date and fire an...
1
by: =?Utf-8?B?eFNBTkRJeA==?= | last post by:
I cant get i tunes/ quicktime working on the computer, I had both of these before but they are not working now for some reason. Advice given on Apple site was to uninstall and then install...
1
by: dan.allen.dc | last post by:
I am looking for a quick sanity check, to make sure I my view of a problem is reasonable. Our organization just upgraded from Access 2003 to Access 2007. One of our MS Access databases is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.