473,385 Members | 1,402 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,385 software developers and data experts.

How to add a new row to a DataList

Rod

I'm new to both SQL server and asp.net so please excuse the dumb question.

I have a table in SQL server that has an identity column and also some
columns that are marked as Not Null.

In asp.net I put this table into a dataset then display it in either a
DataList or a DataGrid.

I want to add a new row so I presume I need a button that will add a row to
the dataset. But how do I sort out the identity field.

I could create the blank row in the database first which gives me the id,
but then the Not Null fields will start demanding data. Seems like a Catch
22.

Please advise!

Many thanks in advance.

Rod
Mar 2 '07 #1
7 2448
"Rod" <Ro**********@Hotmail.comwrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
But how do I sort out the identity field.
Can you explain a bit more what you mean by "sort out" the identity
field...?

When you add a new row to a SQL Server table which contains an identity
field, you don't actually provide a value for that field - SQL Server
generates it for you automatically... If you need to know what the
automatically generated ID of the new record is, use SELECT SCOPE_IDENTIY()
within the same SQL batch...

http://www.google.co.uk/search?hl=en...DENTITY+&meta=
Mar 2 '07 #2
Rod

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:O4**************@TK2MSFTNGP02.phx.gbl...
"Rod" <Ro**********@Hotmail.comwrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
>But how do I sort out the identity field.

Can you explain a bit more what you mean by "sort out" the identity
field...?

When you add a new row to a SQL Server table which contains an identity
field, you don't actually provide a value for that field - SQL Server
generates it for you automatically... If you need to know what the
automatically generated ID of the new record is, use SELECT
SCOPE_IDENTIY() within the same SQL batch...

http://www.google.co.uk/search?hl=en...DENTITY+&meta=

OK I can first create a new row in the SQL table and get the ID, but because
some fields are set to Not Null I have to give them data. But the user has
not yet provided any data.

I could first create the new row in the DataSet without an identity, get the
data for the row (forcing the user to fill in the not null fields) and then
create a new row in the SQL table now I have all the data. I was just
feeling uncomfortable about having a row in my Dataset without an identity
so I was wondering what the proper way of doing it is.

PS thanks for the SELECT SCOPE_IDENTIY tip.
Mar 2 '07 #3
"Rod" <Ro**********@Hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
OK I can first create a new row in the SQL table and get the ID, but
because some fields are set to Not Null I have to give them data. But the
user has not yet provided any data.
Why do you need to create a row *before* the user has provided any data for
it...???
Mar 2 '07 #4
Rod

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:Oy**************@TK2MSFTNGP05.phx.gbl...
"Rod" <Ro**********@Hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>OK I can first create a new row in the SQL table and get the ID, but
because some fields are set to Not Null I have to give them data. But the
user has not yet provided any data.

Why do you need to create a row *before* the user has provided any data
for it...???
To get the ID, but maybe I can live without it, Or at least until after the
user has entered the data.
Mar 2 '07 #5
"Rod" <Ro**********@Hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Why do you need to create a row *before* the user has provided any data
for it...???

To get the ID, but maybe I can live without it, Or at least until after
the user has entered the data.
Apologies - I *really* can't see why you need the ID of a record until it's
been created... What possible use can it be to you...?
Mar 2 '07 #6
Howdy,

I suspect he's just switched from MS Access database, in which id is
returned even if you haven't actually inserted anthing.
--
Milosz
"Mark Rae" wrote:
"Rod" <Ro**********@Hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Why do you need to create a row *before* the user has provided any data
for it...???
To get the ID, but maybe I can live without it, Or at least until after
the user has entered the data.

Apologies - I *really* can't see why you need the ID of a record until it's
been created... What possible use can it be to you...?
Mar 2 '07 #7
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:C4**********************************@microsof t.com...
I suspect he's just switched from MS Access database, in which id is
returned even if you haven't actually inserted anthing.
Hmm - you might be right...
Mar 2 '07 #8

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

Similar topics

1
by: pete K | last post by:
Is it possible in asp.net to have a datalist in the itemtemplate of another datalist? For example: <asp:datalist id="MyList" runat="server"> <ItemTemplate> <table border="0" width="300">...
4
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
0
by: Les Caudle | last post by:
I have a menu system composed of a DataList nested inside a DataList. The outer DataList has it's DataSource (composed of a DataSet with two tables linked by a CategoryPagesRelation Relation) set...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.