ASP.NET - Data Table
Asked By samantha jyesta
08-Sep-10 01:56 PM
Hi all
I've 3 labels with 3 textboxes , a button and a grid view; when i click on the button the values of the textboxes must be shown in the gridview and the data that we entered in the textboxes must be cleared..i finished doing it..but my requirement is that when i enter the data to the textboxes for second time ,the values must be added to the gridview..
but when do this, my new values getting replacing in the gridview..
***Here im not using Any DataBase Connections***
plz help me out...
bryan tugade replied to samantha jyesta
Hi,
Well the problem is that the data that has been bind to your gridview are not stored in your database. The tendency is that when the postback event triggers, it refresh all the control in the page. I suggest create a database then put the data in that database in able for you to retrieve it anytime you want.
Thats it. Happy Coding.
[ Kirtan ] replied to samantha jyesta
Snippet
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = null;
dt = new DataTable();
dt.Columns.Add("Username");
dt.Columns.Add("Password");
Session["MyTable"] = dt;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["MyTable"];
string username = TextBox1.Text;
string password = TextBox2.Text;
DataRow dr = dt.NewRow();
dr[0] = username;
dr[1] = password;
dt.Rows.Add(dr);
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
}

samantha replied to [ Kirtan ]
Thank u so much friend..
Actually I did the same but two modifications are there in my coding. I kept the data in the session but i got confused where to get the data from the session..Can u plz tell me about Sessions..if possible...
Thank u,
$@M!
[ Kirtan ] replied to samantha
you can get the data From Session and Write Data to Session at any page even you can retrieve that DataTable on other page too .,
to store the Data
Session["VarName"] = your Data
when retriving
<DataType> v1 = <DataType>Session["VarName"]
while retrieving the data Casting is needed as Session Stores data as Object so we need to Convert Data While retriving it from session
samantha replied to [ Kirtan ]
Thank u friend..
Can u tell me about image uploading in asp.net(c#). The path of the image should be stored as a binary format and the image should displayed when i click on a button.
[ Kirtan ] replied to samantha
you mean you want to store an Image as Binary In SQL Server Database and Want to Retrieve it when you click on Button ?
[ Kirtan ] replied to samantha

In Database i Created Table ImageTable with Two Column
ID and Image
ID = type of int
and
Image is type of varbinary(MAX)
protected void btnInsertData_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == true)
{
int id = int.Parse(txtID.Text);
/* read Image Data into byete array */
byte[] ImageData = FileUpload1.FileBytes;
/* Connect to database and Write Data into Database */
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("insert into ImageTable(ID,Image) values(@ID,@Image)", con);
comm.Parameters.AddWithValue("@ID", ID);
comm.Parameters.AddWithValue("@Image", ImageData);
comm.ExecuteNonQuery();
con.Close();
}
}
protected void btnReadImageData_Click(object sender, EventArgs e)
{
int ID = int.Parse(txtID.Text);
/* Connect to database and Write Data into Database */
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select Image from ImageTable where id=1", con);
comm.Parameters.AddWithValue("@ID", ID);
object ImageBinary = comm.ExecuteScalar();
Response.BinaryWrite((byte[])ImageBinary);
con.Close();
}

Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B)What is a Daemon threads and how can a thread be created as Daemon? (A) How is shared data managed in threading? (I) Can we use events with threading? (A) How can we know objects in Remoting? (A) What are the ways in which client can create object on server in CAO model? (A) Are CAO stateful in nature? (A) To create objects in CAO A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object
How to autorefresh a gridview In a ASP.NET page I want to refresh only a gridview in time interval of 30 secs instead of autorefresh the whole page. How to do this. . . . ??? means whats the codeto write?? plz help me out. . . . . . . advance thanks grid in updated panel. And then on the timer's time elapsed event updated your data grid. You can refresh the data of grid at certain time interval using Ajax update panel. Please check the following article for more details about the logic and code. http: / / asp-net-csharp-vb.blogspot.com / 2009 / 06 / auto-refresh-data-on-page-using-ajax.html Hope
SHEET TO DATABASE USING STORED PROCEDURE Hii, I want know how to import excel sheet data into databse using stored procedure in sql server Use this - INSERT Personal (Name, ID) SELECT Name, ID FROM OPENROWSET('MSDASQL', 'Driver = {Microsoft Excel hi. . Follow this link . . http: / / www.aspsnippets.com / Articles / Read-and-Import-Excel-Sheet-into-SQL-Server-Database-in-ASP.Net.aspx HI try htis Stored Procedures For this article I have created two stored procedures SheetName varchar ( 20 ), @FilePath varchar ( 100 ), @HDR varchar ( 3 ), @TableName varchar ( 50 ) AS BEGIN DECLARE @SQL nvarchar ( 1000 ) IF OBJECT_ID ( @TableName , 'U' ) IS NOT NULL SET @SQL = 'INSERT INTO ' + @TableName + ' SELECT
tracking the user in asp.net using sql server hi friends, how to tracking the user in asp.net using sql server. please give in detail. thanks. I think you'll need to be more specific about
using LINQ in asp.net 3.5 ASP.NET hi friends, please give using LINQ in asp.net 3.5 examples, eg: table employee fields eid, ename, esal how to write asp.net using LINQ. please give the steps and code, thanks. you can right it like