Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change Value of a Field
Message
De
23/07/2009 13:50:53
Joel Whitehead
Ccs Central Computer Services Inc.
Thunder Bay, Ontario, Canada
 
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01414003
Message ID:
01414009
Vues:
38
>>Not sure if this is the correct place to post this question, but here goes...
>>
>>I have a VB 2008 data entry form that uses ADO.NET to link to a SQL Server 2008 Developer's Edition Database. Everything is working fine, but when I add a new record, I would like to programmatically set some fields to certain values. I know where to put the code, but have no idea what line of code lets me change the value of a field. In Visual Foxpro, of course I would type REPLACE fieldname WITH value. How the heck do I do this in VB?
>
>If you want the values to be some default values, then, IMHO, the simplest way would be to set default values in the table (in SQL Server) directly.
>
>Otherwise you need to use UPDATE command in SQL Server to set the values to whatever values you want them to be (or INSERT command for a new record).

But can VB talk to its own dataset in its own form and set the value of a simple field programmatically? I am new to VB / SQL server programming and cannot believe how difficult such a simple task seems. It was so straightforward in Visual Foxpro (or at least seems that way since I have so much experience with VFP).

Here is why I am trying to do this. I have set up a simple Customers database which has a primary key in SQL Server - its data type is uniqueidentifier. I have set its default value to NewID(). A simple INSERT command in SQL correctly populates the primary key field (cuspk). Feeling pretty good at this point about my progress! ;o)

Then comes the VB nightmare. I get a simple for data entry working, but cannot for the life of me get VB to ignore the value of the primary key field and let SQL Server populate it... keep getting "Column cuspk does not allow nulls". If I set the default value of the cuspk field in the dataset to 00000000-0000-0000-0000-000000000000 (using the designer for the data set), my form works great and sends the record back to the SQL table (but of course a bunch of zeros is not what i really want in cuspk). So I figure I am almost 'there'! I even found code to set a variable to a new GUID:

Dim xGUID As String = System.Guid.NewGuid.ToString()
MsgBox(xGUID)

This seems to work as shown in the message box I get in VB. So I figure I just need to set cuspk to xGUID - simple right? Wrong! So far this seems next to impossible. This is programming 101 to me - but how is it that VB 2008 - the latest version - can't do something so simple? What am I missing here? Seems to me such a basic function (add new record to SQL database with primary key without crashing) should be easy. Maybe it is, but I can't see the forest for the trees! ;o) HELP!!!!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform