473,466 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

inserting null values

1 New Member
hi...

can you tel me how to insert null values in Access table using Vb code....

actually i want to store record having some fields with null values...plz....... i mean error is in query statement... saying "Invalid use of null value.." ... :)
Jul 31 '06 #1
8 11115
Hemant Pathak
92 Recognized Expert New Member
Hi
try to use this Query of inserting the value of Access Table

insert into tablename values('" & null & "'" & "'")
Jul 31 '06 #2
Mahesh_Bote
26 New Member
why r u inserting NULLS? If u wants to insert NULL in a column, don't insert value for the said field. instead of this field, insert values for other columns.

i.e. u have table with A, B, C, D columns, and if u want to insert NULL into B, then use

Insert Into <Table Name> (A, C, D) Values (<Values for A>, <Values for C>, <Values for D>


Mahesh
:) :) :)
Aug 1 '06 #3
sashi
1,754 Recognized Expert Top Contributor
hi here,

the best practise will be defining a default value during the design time of your table.. let it take care the rest.. take care..
Aug 1 '06 #4
gman_00ph
9 New Member
why r u inserting NULLS? If u wants to insert NULL in a column, don't insert value for the said field. instead of this field, insert values for other columns.

i.e. u have table with A, B, C, D columns, and if u want to insert NULL into B, then use

Insert Into <Table Name> (A, C, D) Values (<Values for A>, <Values for C>, <Values for D>


Mahesh
:) :) :)
What if there is a value in B
and i want to put a null value in B

at this point i cant update it
not unless i use to insert this value=" " to B
Aug 2 '06 #5
thisbetom
1 New Member
If you are passing the variables to a dataset its "dbnull.value"
daTableAdapter.Insert(PK.tostring, Column2Data.2String, dbnull.Value)

You might be able to concatenate it into a string update query as well
Apr 29 '07 #6
Befo
1 New Member
hi...

can you tel me how to insert null values in Access table using Vb code....

actually i want to store record having some fields with null values...plz....... i mean error is in query statement... saying "Invalid use of null value.." ... :)
try passing the null value (access keyword) as a string in the sql query
i.e.
sql1="INSERT INTO tblMiTabla (Col1,Col2,Col3,Col4)
sql2="VALUES (" & var1 & "," & var2 & "," & IIf(IsNull(var3),"Null",var3) & ")"

where var1,var2,var3,var4 are variable names
Jun 15 '07 #7
pureenhanoi
175 New Member
What if there is a value in B
and i want to put a null value in B

at this point i cant update it
not unless i use to insert this value=" " to B
Becarefully using of Null value. GMan_OOph have right way for inserting Null value. But this happent if B field type are text, datetime, or several other types. If B field type are number, Yes/No, they have default values so that u cant let it Null by this way. U must use
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName(A,B,C,D) VALUES(" & a & ",Null," & c & "," & d & ")" 
When Updating Null value, if u replace old value by new value, so there is no problem. But if u plant add new value into old value, so u must check it first.
Expand|Select|Wrap|Line Numbers
  1. sql = "SELECT * FROM tableName"
  2. if rs.state<> 0 Then rs.Close
  3. rs.Open sql, cnxn, 1,3
  4.       If isNull(rs.Fields("B") Then
  5.              rs.Fields("B") = newValue
  6.       Else
  7.              rs.Fields("B") = rs.Fields("B") + newValue
  8.       End If
  9. rs.Update
  10.  
Remember, in ur database, select Require = No, and AllowNull = Yes for this field before u can set Null value for it.
Jun 16 '07 #8
hariharanmca
1,977 Top Contributor
hi...

can you tel me how to insert null values in Access table using Vb code....

actually i want to store record having some fields with null values...plz....... i mean error is in query statement... saying "Invalid use of null value.." ... :)
Expand|Select|Wrap|Line Numbers
  1. strSql=""
  2. strSql="Insert Into" &  <Table Name> 
  3. strSql=strSql & "(A"
  4. strSql=strSql & iif(isNull(<Values for B>),  "",  ",B")
  5. strSql=strSql & iif(isNull(<Values for C>),  "",  ",C")
  6. strSql=strSql & iif(isNull(<Values for D>),  "",  ",D")
  7. strSql=strSql & ") Values (" & <Values for A>
  8. strSql=strSql & iif(isNull(<Values for B>),  "",  "," & <Values for B>)
  9. strSql=strSql & iif(isNull(<Values for C>),  "",  "," & <Values for C>)
  10. strSql=strSql & iif(isNull(<Values for D>),  "",  "," & <Values for D>)
  11. strSql=strSql & ")"
I think this will help you
Jun 16 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: GreenFROG Design | last post by:
Data Processing and SQL INSERTING Hello guy's i'm faced with a horrible dilemma i have whole dictionary that i have to enter into a database. I have all the text and i would like to convert it...
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
9
by: Andrew Banks | last post by:
I'm running the following code in a C#.NET page and it doesn't enter the values into the DB. I'm certain the problem is to do with the txtBirth field. It allows users to enter a DOB as dd/mm/yyyy...
2
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from...
1
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO...
7
by: ebindia0041 | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, Asp.net 1.1 with c# I'm inserting simple records into a table. But one...
9
by: Oonz | last post by:
Hi Friends, How can we insert records in sorted order like consider a table No Name Phone 1 test1 12345 1 test1 23455 2 test2 68638
0
by: gp | last post by:
I am and have been using PDO for about a year now...and have finally gotten around to solving the "DB NULL value" issues I ran into early on... I am looking for suggestions and techniques to...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
2
by: aeblank | last post by:
THE PROBLEM I'm running into performance issues generating and storing a randomly created graph in a SQL Server database. I have a T-SQL script that generates a graph, and then randomly connects the...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.