Sunday, February 12, 2012
Cant insert the value NULL into column
Unable to modify tblship_sched
Can't insert the value NULL into column mfg_qty table qc.dbo.Tmp_tblship_sched; Column doesn't allow nulls.
Insert fails.
What is or where is the Tmp table?
Thank you.I am not sure what you mean when you ask where the table is.
SELECT * FROM SYSOBJECTS WHERE NAME = 'Tmp_tblship_sched'
If the table exists then I suggest you check the column constraint for the table in question. Looks like it has a NOT NULL constraint.
You can disable it for your insert.
Good Luck!
Cant insert NULL to DateTime field
Hi I'm using DetailView and I have a text box which show the date. I have formated the date as shortDate {0:d} format. I want to insert/update null if that text box is empty.
I have tried putting null value in my Update statement in sqlDataSource. And I'm getting error saying can't convert varchar to smalldatetime.
If I don't set null value as above, some large date (01/01/2033) has been inserted in my database.
Can anyone help me?
Moe
insert DBNull.Value not "null"Hope this help|||Thanks a lot.. :)|||Dear,Can you explain where I put this code? I am newbie and have the same with formview, and I wonder where to enter this DBNULL?Can you help please?|||
Here is sample code:
sqlStmt ="insert into Emp (FirstName,LastName,Date) Values (?,?,?) ";conString ="Provider=sqloledb.1;user id=sa;pwd=;database=northwind;data source=localhost";cn =new OleDbConnection(conString);cmd =new OleDbCommand(sqlStmt, cn) ;cmd.Parameters.Add(new OleDbParameter("@.FirstName", OleDbType.VarChar, 40));cmd.Parameters.Add(new OleDbParameter("@.LastName", OleDbType.VarChar, 40));cmd.Parameters.Add(new OleDbParameter("@.Date", OleDbType.Date)); cmd.Parameters["@.FirstName"].Value = txtFirstName.Text;cmd.Parameters["@.LastName"].Value = txtLastName.Text;if ((txtDate.Text =="") ){cmd.Parameters["@.Date"].Value = DBNull.Value;}else{cmd.Parameters["@.Date"].Value = DateTime.Parse(txtDate.Text);}cn.Open();cmd.ExecuteNonQuery();Label1.Text ="Record Inserted Succesfully";
Cant import an Access table due to null values.
which some records have null values in fields that allow null values?
Wouldn't the table's design be imported first, bringing the columns'
"allow nulls" attribute with it?
I'm dealing with both text and numeric columns. Not all columns
containing nulls cause an error.
Thanks,
Bob C."Bob C." <bcanavan@.bmghomes.com> wrote in message
news:2e5623fb.0402201301.4098061b@.posting.google.c om...
> Question: Why would I not be able to import an Access 97 table in
> which some records have null values in fields that allow null values?
> Wouldn't the table's design be imported first, bringing the columns'
> "allow nulls" attribute with it?
> I'm dealing with both text and numeric columns. Not all columns
> containing nulls cause an error.
> Thanks,
> Bob C.
It's hard to say (at least for me) what the issue may be without more
information. In particular, how are you importing the table, and what is the
exact error message you see? Also, which version of SQL Server are you using
as the target for the import? If you're using the upsizing wizard, you may
want to post this in an Access newsgroup as well, as it's an Access tool,
not an MSSQL one.
Simon|||Thanks, Simon.
I'm using DTS to import to SQL2k. Sorry for not posting that
information.
It turns out that only two of the columns in my Access table were
affected, and they both disallowed nulls. This attribute was one I
set after the Access database had been in production awhile, and the
db manager asked that nulls for those columns be blocked. I think
what happened was that nulls already in those columns were
grandfathered(strange that I wasn't warned when I set the "allow
nulls" attribute to false), and the new table structure in SQL2k
correctly carried over the attribute - tripping over the grandfathered
nulls when I tried to import them.
Thanks for your help.
Bob C.