Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts

Sunday, February 19, 2012

Inserting record into table as the first record

Hi all,

I would like to know whether i can insert a record as the first record to a table which is not empty using sqlserver(that is i need to display that record as the first record)....

Please help me...

Regards,

MathewYou can not rely on position of a record in a table.
Always use order by Asc or Desc to make record first or last.

Good Luck.

Inserting problem with sqlserver and vb.net

hi there i ve got a quick question regarding table and adding primary key and values
Basically i have a empty table called ReligionType and have two fields ReligionID and ReligionName. I would like to add a new data into this table (i set the indentity and identity seed in sql server but when i execute the value in sqladapter it give me error on

"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll"

This is the code that i wrote in vb.net


con2.Open() //sql connection

Me.SqlDataAdapter2.Fill(DataSet1)

Me.SqlInsertCommand2.CommandText() = "Insert into ReligionType(ReligionName) Values (@.ReligionName) SELECT @.@.identity As 'ReligionID' GO"

Me.SqlInsertCommand2.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

Me.SqlInsertCommand2.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.ReligionName", System.Data.SqlDbType.NVarChar, 20)).Value = inputdata.Text

Me.SqlInsertCommand2.ExecuteNonQuery()

'Me.SqlDataAdapter2.Fill(DataSet1)
con2.Close()

so where did i go wrong ?
please helpHi,
i suppose the SQL should look like this.

"Insert into ReligionType(ReligionName) Values (@.ReligionName); SELECT @.@.identity As 'ReligionID' GO"

Hope this helps.

Regards...|||thanks but it still doesnt work|||The GO command would cause a problem...

The GO command isn't a T-SQL command (although it works in Query Analyzer). Take it out and give it a try.
I haven't looked too hard at the rest of the code...|||Still when i have remove the word go it still doesnt work
ps... i forgot to mention that the data in the table is currently empty

and also have type try and catch statement and this is the result of message

"Object reference not set to an instance of an object."

so what did i do wrong ?

Inserting Nulls with DTS

I am using a DTS package to copy data from a flat file to a table. I need for fields that are empty to be changed to nulls in the output. I wrote a VB Script to do this, but now it takes about 10 times longer that when I used the Copy transformation. Is there a faster way to do this?

I haven't tried the Trim transformation yet. (I'm waiting for my load to finish.) Will that place nulls in the output if a field is empty?Originally posted by jsneeringer
I am using a DTS package to copy data from a flat file to a table. I need for fields that are empty to be changed to nulls in the output. I wrote a VB Script to do this, but now it takes about 10 times longer that when I used the Copy transformation. Is there a faster way to do this?

I haven't tried the Trim transformation yet. (I'm waiting for my load to finish.) Will that place nulls in the output if a field is empty?

Hi,
1-in your SQL Server Table ( Destination DB) set a default value for the field(s), so when you attemp to insert Null value in that Field, the specified default vale will be insert. ( the way of inserting is not important . It can be DTS!!)

2- you can also write a Instead Of Trigger on your Table For Insert, so process the field value, if it's Null , write empty.

Hope that help you