Click here to Skip to main content
15,901,505 members
Home / Discussions / C#
   

C#

 
Generalfound a solution :-) Pin
Stephan Wright19-Jul-04 23:04
Stephan Wright19-Jul-04 23:04 
Generalvery urgent. about audio mixers Pin
karpurapu_z19-Jul-04 20:37
karpurapu_z19-Jul-04 20:37 
GeneralGlobal variables and ViewState Pin
Alex Getman19-Jul-04 20:12
Alex Getman19-Jul-04 20:12 
GeneralRe: Global variables and ViewState Pin
Syed Abdul Khader20-Jul-04 4:08
Syed Abdul Khader20-Jul-04 4:08 
Generaledit box display formatting Pin
RonBou19-Jul-04 19:10
RonBou19-Jul-04 19:10 
Generalinpout32.dll Pin
ahmedadelfarid19-Jul-04 18:57
ahmedadelfarid19-Jul-04 18:57 
Generalurgent ! handling multiple data tables in a dataset Pin
sharpX19-Jul-04 18:40
sharpX19-Jul-04 18:40 
GeneralRe: urgent ! handling multiple data tables in a dataset Pin
Heath Stewart20-Jul-04 9:49
protectorHeath Stewart20-Jul-04 9:49 
First - always bind to the DataSet, then set the binding member (like DataGrid.DataMember) to the name of the DataTable when possible. This allows you to use relationships to navigate tables.

Second - the problem is that you haven't defined your DataTable yet. If your SQL database would use an identity field (auto-incrementing), then you must set the DataColumn.AutoIncrement property to true. The easiest way to do this is to add a new DataSet to your project in VS.NET and use the designer to create a DataSet. Create elements that represents DataTables, and elements under those represent fields, which you can set properties for in the PropertyGrid. Then instead of using a generic DataSet, you can instantiate the DataSet derivative that you just created, which will - when instantiated - have the correct structure.

The problem you're having is that an identity column is not being assigned automatically, and since identity columns are typically non-null, you can insert the DataRow because that identity column would be null. The solution I provided above fixes this.

It's important to note that if you use a SqlDataAdapter to easily update a database (see SqlDataAdapter.Update(DataSet) in the .NET Framework SDK) your InsertCommand should be both an INSERT and SELECT SQL statement combined (INSERT ...; SELECT ...). This makes sure that the identity columns are updated to the correct numbers once inserted into a table (since the database may assign different numbers in a multi-user environment). If you just assign the auto-assigned numbers in your local DataSet will match those in the database, you will have problems.

You should read about ADO.NET more in the .NET Framework SDK and I suggest you try using the designers to create connections, commands, and adapters (as well as data sets as I mentioned above) and view the source code to see how it's done. Learning by example can often open the flood gates of understanding (so long as you have at least some knowledge of what's going on...which is why you should read the class and member documentation for those classes and members being used).

 

Microsoft MVP, Visual C#
My Articles
QuestionHow can I display 2 forms, one after the other? Pin
arik_a19-Jul-04 18:08
arik_a19-Jul-04 18:08 
AnswerRe: How can I display 2 forms, one after the other? Pin
MKlucher19-Jul-04 18:28
MKlucher19-Jul-04 18:28 
GeneralRe: How can I display 2 forms, one after the other? Pin
arik_a19-Jul-04 22:47
arik_a19-Jul-04 22:47 
QuestionHow to realize Web control's context menu by c# Pin
nakey_yang19-Jul-04 17:18
nakey_yang19-Jul-04 17:18 
AnswerRe: How to realize Web control's context menu by c# Pin
Nick Parker19-Jul-04 17:29
protectorNick Parker19-Jul-04 17:29 
GeneralVery Urgent Please -- Overloading ++ operator doesn't function as intended. Pin
Member 112523619-Jul-04 17:12
Member 112523619-Jul-04 17:12 
GeneralRe: Very Urgent Please -- Overloading ++ operator doesn't function as intended. Pin
Javier Lozano19-Jul-04 18:06
Javier Lozano19-Jul-04 18:06 
GeneralRe: Very Urgent Please -- Overloading ++ operator doesn't function as intended. Pin
Heath Stewart20-Jul-04 10:04
protectorHeath Stewart20-Jul-04 10:04 
GeneralBinary Data over network Pin
joelwwk19-Jul-04 17:11
joelwwk19-Jul-04 17:11 
GeneralRe: Binary Data over network Pin
Heath Stewart20-Jul-04 10:19
protectorHeath Stewart20-Jul-04 10:19 
GeneralMissing Authorization http header Pin
darma_m19-Jul-04 15:37
darma_m19-Jul-04 15:37 
GeneralResizing help Pin
Wjousts19-Jul-04 15:18
Wjousts19-Jul-04 15:18 
GeneralRe: Resizing help Pin
Heath Stewart20-Jul-04 10:25
protectorHeath Stewart20-Jul-04 10:25 
Questionhow to get the system imagelist Pin
noosword19-Jul-04 14:46
noosword19-Jul-04 14:46 
AnswerRe: how to get the system imagelist Pin
Heath Stewart20-Jul-04 4:29
protectorHeath Stewart20-Jul-04 4:29 
GeneralRe: how to get the system imagelist Pin
noosword20-Jul-04 19:02
noosword20-Jul-04 19:02 
GeneralRe: how to get the system imagelist Pin
Heath Stewart21-Jul-04 3:59
protectorHeath Stewart21-Jul-04 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.