hello

I want to create a page,where there will be a gridview,with 2 columns.
1st column will have Numbers..1,2,3,4,5........as much as user want.

next column is where people will insert data,say a,b,c,d,e,f,g.....

After pressing the button,
1,a 2,b 3,c ....all these wil be inserted in database rows.

can somebody please help me ,how to do this.

Also how to write stored procedure for this insert statement,means do I have to use xml,oe is it possible to so without using xml....

I dont know how to use xml .

I am using sql server 2005 n visual studio 2008

thank you

well I want to correct one line
"
1,a 2,b 3,c ....all these wil be inserted in table rows."

well is this task so difficult that I am not getting any reply.

I really need help in this

thank you

Well, as per the stickies, you show us what you have, explain the problem you have with it, we'll help you try fix it, we wont do it all for you

okay I am sorry for that.

this is what I want to know


I want to insert multiple records,that user will insert in gridview ino databse.For this I am told to use XML.

My gridview will have two columns.

here is my stored procedure.

ALTER PROCEDURE [dbo].[InsertTOCHSCounterStyle]
(

@DsXML xml
)

AS
BEGIN

Declare @TOCHSCounterNumber as int;
Declare @TOCHSCounterLabelText as varchar(4);


Declare @returnVal as int;

.
SET NOCOUNT ON;
DECLARE GetNumber CURSOR for SELECT ParamValues.ID.value('.','VARCHAR(20)')FROM @DsXML.nodes('/TableOfContent/Number') as ParamValues(ID)

OPEN GetNumber

FETCH NEXT FROM GetNumber into @TOCHSCounterNumber ;

DECLARE Getlabeltext CURSOR for SELECT ParamValues.ID.value('.','VARCHAR(20)')FROM @DsXML.nodes('/Data/name') as ParamValues(ID)

OPEN Getlabeltext

FETCH NEXT FROM Getlabeltext into @TOCHSCounterLabelText ;

WHILE @@FETCH_STATUS = 0

begin

--Here inesrt query to insert into db

Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText) values (@TOCHSCounterStyleID,@TOCHSCounterNumber,@TOCHSCounterLabelText)

-- Here you can write your queries accroding to the condition

set @returnVal = @returnVal + 1;

FETCH NEXT FROM GetNumber into @TOCHSCounterNumber ;

FETCH NEXT FROM Getlabeltext into @TOCHSCounterLabelText ;

end

CLOSE GetNumber

DEALLOCATE GetNumber

CLOSE Getlabeltext

DEALLOCATE Getlabeltext

END

I have limited knowledge about how to use xml.

DO i have to create an empty .xml file???????

Also what command shall I write in my C# code so that data enetred in gridview will be stored in xml file.this what I have done and its giving me error.....

DataSet ds = new DataSet();
ds = (DataSet)(dgItem.XmlDataSource1);
ds.WriteXml("DsXML.xml");

do i have to create DsXML.xml file or it will be automatically generated.

ALso do I have to use xmlDataSource??????

please help me.

Thank You.

It always puzzles me when people insist that XML needs to be used when you have direct access to the database, why over process.

Your dataset should be the datasource of your grid, and already exist, you shouldnt need to do a new dataset and then set a value it..

the file should be generated,..

Because there is no direct control for insertion for datagrid,u hav do it by binding data to SqlDataSource.

protected void Button1_Click1(object sender, EventArgs e)
{

    int id = Convert.ToInt32(TextBox1.Text);
    SqlDataSource1.InsertCommand = "insert into stu_id values("+ id +")";
    SqlDataSource1.Insert();
}

where stu_id is a tablei n my sqlserver2005.,to which i want to insert data from datagrid

with this code,ur data will be inserted into database when u insert data in textbox and click a button.

U don't need to bother about XML for this.

Edited 3 Years Ago by Nick Evan: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.