Click here to Skip to main content
16,011,170 members
Home / Discussions / Database
   

Database

 
AnswerRe: TRICKY - How to SELECT TOP X records when using UNION? Pin
Richard Deeming13-Sep-02 6:01
mveRichard Deeming13-Sep-02 6:01 
GeneralSQLDMO & DTS Pin
Paul Watson10-Sep-02 7:08
sitebuilderPaul Watson10-Sep-02 7:08 
GeneralRe: SQLDMO & DTS Pin
Nick Parker11-Sep-02 13:12
protectorNick Parker11-Sep-02 13:12 
Questionsp_OASetProperty limitations? Pin
Jeremy Falcon6-Sep-02 7:50
professionalJeremy Falcon6-Sep-02 7:50 
AnswerRe: sp_OASetProperty limitations? Pin
Jeremy Falcon6-Sep-02 9:33
professionalJeremy Falcon6-Sep-02 9:33 
AnswerRe: sp_OASetProperty limitations? Pin
Nick Parker11-Sep-02 8:40
protectorNick Parker11-Sep-02 8:40 
GeneralRe: sp_OASetProperty limitations? Pin
Jeremy Falcon12-Sep-02 5:56
professionalJeremy Falcon12-Sep-02 5:56 
GeneralInserting values into sql table with C# help Pin
halbichmi6-Sep-02 6:13
halbichmi6-Sep-02 6:13 
I have several string and decimal values that I have to enter into my table through an sql statement. I have one problem. When one of my date fields is null, the table automatically enters the default 1/1/1900. I need to find another way around this. That field needs to stay blank if it is originally blank.

what my code looks like:

string connstr = "my connection to db";
string sSQLCommand = "INSERT INTO t340(cmd_dsg,trns_cd,proc_act_cd,inp_act_cd," + "blk_tkt_no,blk_tkt_dt,seq_no,updt_cd,jono,eor,comt_ref_no,oblg_ref_no_spiin,cost_cen_mgr,docu_dt,act_amt,wi_fed_govt_cd,oblg_stat_cd,oblg_expir_dt,jv_no,oblg_ty_cd,amd_no,qty,wt_lbs,hrs,nomenclature,clin,acrn,mod_no,subjono,ifs_docu_no,lbr_pay_pd_no,prod_ind,reject_cd,correction_cd,load_date)" +
"VALUES('" + cmd_dsg + "','" + trns_cd + "','" + proc_act_cd + "','" + inp_act_cd + "','" + blk_tkt_no + "','" + blk_tkt_dt + "','" + seq_no + "','" + updt_cd + "','" + jono + "','" + eor + "','" + comt_ref_no + "','" + oblg_ref_no_spiin + "','" + cost_cen_mgr + "','" + docu_dt + "'," + act_amt + ",'" + wi_fed_govt_cd + "','" + oblg_stat_cd + "','" + oblg_expir_dt + "','" + jv_no + "','" + oblg_ty_cd + "','" + amd_no + "'," + qty + "," + wt_lbs + "," + hrs + ",'" + nomenclature + "','" + clin + "','" + acrn + "','" + mod_no + "','" + subjono + "','" + ifs_docu_no + "','" + lbr_pay_pd_no + "','" + prod_ind + "','" + reject_cd + "','" + correction_cd + "','" + ldate + "');";
//Create the command object

SqlConnection myConnection = new SqlConnection(connstr);
SqlCommand cmdAdder = new SqlCommand(sSQLCommand, myConnection);
myConnection.Open();
int nNoAdded = cmdAdder.ExecuteNonQuery();
myConnection.Close();

Everything else works. I need to know if there is another way to insert each value and to be able to use an if statement for when the field is blank. I was able to do this in VB but I am having to convert this program.

this is what the VB looked like:

qstr = "Select * from t340 where cmd_dsg = '1111111111111'"

Set temprec = New ADODB.Recordset
temprec.CursorType = adOpenDynamic
temprec.CursorLocation = adUseClient
temprec.Open qstr, cnn1, adOpenKeyset, adLockOptimistic, adCmdText

temprec.AddNew
temprec!cmd_dsg = cmd_dsg
temprec!trns_cd = trns_cd
temprec!proc_act_cd = proc_act_cd
temprec!inp_act_cd = inp_act_cd
temprec!blk_tkt_no = blk_tkt_no
If blk_tkt_dt <> "" Then
temprec!blk_tkt_dt = blk_tkt_dt
End If
temprec!seq_no = seq_no
temprec!updt_cd = updt_cd
temprec!jono = jono
temprec!eor = eor
temprec!comt_ref_no = comt_ref_no
temprec!oblg_ref_no_spiin = oblg_ref_no_spiin
temprec!cost_cen_mgr = cost_cen_mgr
If docu_dt <> "" Then
temprec!docu_dt = docu_dt
End If
temprec!act_amt = act_amt
temprec!wi_fed_govt_cd = wi_fed_govt_cd
temprec!oblg_stat_cd = oblg_stat_cd
If oblg_expir_dt <> "" Then
temprec!oblg_expir_dt = oblg_expir_dt
End If
temprec!jv_no = jv_no
temprec!oblg_ty_cd = oblg_ty_cd
temprec!amd_no = amd_no
temprec!qty = qty
temprec!wt_lbs = wt_lbs
temprec!hrs = hrs
temprec!nomenclature = nomenclature
temprec!clin = clin
temprec!acrn = acrn
temprec!mod_no = mod_no
temprec!subjono = subjono
temprec!ifs_docu_no = ifs_docu_no
temprec!lbr_pay_pd_no = lbr_pay_pd_no
temprec!prod_ind = prod_ind
temprec!reject_cd = reject_cd
temprec!correction_cd = correction_cd
temprec!load_date = load_date
temprec.Update
temprec.Close

Could someone please help?
GeneralImport diagram to SQL-server 2000 Pin
Rulle6-Sep-02 1:47
Rulle6-Sep-02 1:47 
GeneralRe: Import diagram to SQL-server 2000 Pin
notadood6-Sep-02 2:56
notadood6-Sep-02 2:56 
GeneralRe: Import diagram to SQL-server 2000 Pin
Rulle6-Sep-02 6:57
Rulle6-Sep-02 6:57 
GeneralAutomation Error Pin
bugbuster5-Sep-02 11:35
bugbuster5-Sep-02 11:35 
GeneralRe: Automation Error Pin
notadood6-Sep-02 2:53
notadood6-Sep-02 2:53 
GeneralIdentity Seed/Increment Customize Pin
Robby5-Sep-02 5:25
Robby5-Sep-02 5:25 
GeneralRe: Identity Seed/Increment Customize Pin
Jon Hulatt6-Sep-02 3:55
Jon Hulatt6-Sep-02 3:55 
GeneralLEFT OUTER JOIN leaves rows Pin
Knappen4-Sep-02 10:18
Knappen4-Sep-02 10:18 
Generala sql query question Pin
freeworldbird4-Sep-02 7:54
freeworldbird4-Sep-02 7:54 
GeneralRe: a sql query question Pin
Mazdak4-Sep-02 7:59
Mazdak4-Sep-02 7:59 
GeneralRe: a sql query question Pin
freeworldbird4-Sep-02 8:07
freeworldbird4-Sep-02 8:07 
GeneralRe: a sql query question Pin
Mazdak4-Sep-02 23:24
Mazdak4-Sep-02 23:24 
GeneralRe: a sql query question Pin
Nick Parker4-Sep-02 9:31
protectorNick Parker4-Sep-02 9:31 
GeneralRe: a sql query question Pin
freeworldbird4-Sep-02 16:35
freeworldbird4-Sep-02 16:35 
GeneralRe: a sql query question Pin
freeworldbird5-Sep-02 16:08
freeworldbird5-Sep-02 16:08 
GeneralDatetime in SQL server<>ADO Pin
Rulle3-Sep-02 23:01
Rulle3-Sep-02 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.