Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > How to overcome the NOT ALLOW NULL Error in datagrid?

Thread Tools Display Modes
Old 07-20-2003, 11:46 PM
mikechan8888 mikechan8888 is offline
Join Date: Jul 2003
Location: HK
Posts: 436
Question How to overcome the NOT ALLOW NULL Error in datagrid?

Usually I prefer to do all the data manipulation for my applications by writing codes. But now I need to find a very quick way to do insert, update, delete on a datagrid. So I just pulled a datagrid control on the form, set the datasource and datamember, it works fine for retrieve, update, and delete. But when it comes to insert, I got into problem. Because my application will be an order form, when you click on a button on the form, a new form will pop up with the datagrid. The datagrid will be a grid containing the contact numbers for the order (the relationship is one order form can have many contact person and numbers).

The query will be executed with an order ID as parameter in the where clause. The user will not be able to see the order ID as it will not be user-friendly to ask the users to key in the same order ID whenever they want to insert records into the contact table. The datagrid will display a blank row at the end so I just enter the contact person and contact number into the grid. But when I move the cursor down one row, VB will try to insert the record without knowing the order ID. Of course, it will generate an error message as order ID is defined as NOT NULL in SQL Server for the contact table.

So how can I overcome this problem so that whenever the user finished entering a new row into the datagrid and move to the next row, the order ID will go together with the other fields. I tried the BeforeInsert and AfterInsert events, but looks like they are triggered before actually inserting into the database.

Reply With Quote
Old 07-21-2003, 12:17 AM
pradeep pradeep is offline
Join Date: May 2002
Location: Andhra Pradesh, India
Posts: 484

try this...

Private Sub DataGrid1_BeforeUpdate(Cancel As Integer)
    adodc1.Recordset("orderID") = orderid
End Sub
You won't win if you don't begin.
Reply With Quote
Old 07-21-2003, 05:09 AM
mikechan8888 mikechan8888 is offline
Join Date: Jul 2003
Location: HK
Posts: 436

Thanks for the idea!

It works fine but looks like some other actions will also trigger the BeforeUpdate event. It might be better to move your code to the OnAddNew event.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Empty strings in stored Procedures jfergy Database and Reporting 2 06-12-2003 11:27 PM
Rows that exceed the maximum number of bytes will not be added jollyguy4all Database and Reporting 4 03-27-2003 11:43 AM
problem linuxman25 Database and Reporting 22 01-27-2003 10:36 AM
Controls dont like NULL values in OLEDB Datagrid records. Mikirin Database and Reporting 2 01-25-2002 09:57 AM


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..