Click here to Skip to main content
15,900,258 members
Home / Discussions / C#
   

C#

 
AnswerRe: Whats happening to my objects? Pin
Ed K6-Sep-02 17:47
Ed K6-Sep-02 17:47 
GeneralRe: Whats happening to my objects? Pin
leppie6-Sep-02 18:08
leppie6-Sep-02 18:08 
GeneralRe: Bitwise operators on non byte primitives Pin
leppie6-Sep-02 16:34
leppie6-Sep-02 16:34 
GeneralRe: Bitwise operators on non byte primitives Pin
Rodney S. Foley6-Sep-02 16:57
Rodney S. Foley6-Sep-02 16:57 
GeneralRe: Bitwise operators on non byte primitives Pin
leppie6-Sep-02 17:08
leppie6-Sep-02 17:08 
GeneralRe: Bitwise operators on non byte primitives Pin
Rodney S. Foley6-Sep-02 17:27
Rodney S. Foley6-Sep-02 17:27 
GeneralRe: Bitwise operators on non byte primitives Pin
Jonathan Tan6-Sep-02 23:22
Jonathan Tan6-Sep-02 23:22 
GeneralNeed help with sql insert statement in C# Pin
halbichmi6-Sep-02 6:10
halbichmi6-Sep-02 6:10 
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? Eek! | :eek:
GeneralRe: Need help with sql insert statement in C# Pin
leppie6-Sep-02 7:20
leppie6-Sep-02 7:20 
GeneralRe: Need help with sql insert statement in C# Pin
SimonS6-Sep-02 19:16
SimonS6-Sep-02 19:16 
GeneralRe: Need help with sql insert statement in C# Pin
halbichmi7-Sep-02 3:45
halbichmi7-Sep-02 3:45 
GeneralRecreate My Network Place Pin
D Shen6-Sep-02 3:40
D Shen6-Sep-02 3:40 
GeneralRe: Recreate My Network Place Pin
Ryan Cromwell6-Sep-02 6:00
Ryan Cromwell6-Sep-02 6:00 
GeneralEasy:reference values after dialog show Pin
EdgarBM5-Sep-02 23:57
EdgarBM5-Sep-02 23:57 
GeneralRe: Easy:reference values after dialog show Pin
Stephane Rodriguez.6-Sep-02 0:26
Stephane Rodriguez.6-Sep-02 0:26 
Questionhow to specify the handle for findfirstfile, etc? Pin
Segal5-Sep-02 20:35
Segal5-Sep-02 20:35 
AnswerRe: how to specify the handle for findfirstfile, etc? Pin
Stephane Rodriguez.5-Sep-02 21:06
Stephane Rodriguez.5-Sep-02 21:06 
GeneralRe: how to specify the handle for findfirstfile, etc? Pin
Anonymous5-Sep-02 21:16
Anonymous5-Sep-02 21:16 
GeneralRe: how to specify the handle for findfirstfile, etc? Pin
Stephane Rodriguez.5-Sep-02 21:20
Stephane Rodriguez.5-Sep-02 21:20 
AnswerRe: how to specify the handle for findfirstfile, etc? Pin
leppie5-Sep-02 23:55
leppie5-Sep-02 23:55 
GeneralOpinion Wanted: XML Component Pin
Fredrick P. Lackey5-Sep-02 16:51
sussFredrick P. Lackey5-Sep-02 16:51 
GeneralRe: Opinion Wanted: XML Component Pin
Stephane Rodriguez.5-Sep-02 20:38
Stephane Rodriguez.5-Sep-02 20:38 
GeneralRe: Opinion Wanted: XML Component Pin
Anonymous6-Sep-02 2:55
Anonymous6-Sep-02 2:55 
GeneralRe: Opinion Wanted: XML Component Pin
Stephane Rodriguez.6-Sep-02 3:17
Stephane Rodriguez.6-Sep-02 3:17 
GeneralFloppy Disk Image Pin
TeraCoder5-Sep-02 15:28
TeraCoder5-Sep-02 15:28 

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.