c# - LINQ to SQL Failing to Insert to the Database -
i learning linq , trying insert using linq sql having challenges when inserting showing me incorrect string format when debug no pointing on specific line. can please me made mistake.
save button
list<legal_member> _legalmemberlist = _dc.legal_members.where(a => a.idnumber == txtidnumber.text.tostring()).tolist(); if (rbtnareyouemployed.items[0].selected == true) { viewstate["areyouemployed"] = true; } else { viewstate["areyouemployed"] = false; } if (rbtnissacitizen.items[0].selected == true) { viewstate["issacitizen"] = true; } else { viewstate["issacitizen"] = false; } if (_legalmemberlist != null) { if (_legalmemberlist.count() == 0) { legal_member _legalmember = new legal_member { idnumber = txtidnumber.text, inceptiondate = convert.todatetime(txtinceptiondate.text), legalpreferedname = txtpreferedname.text, initials = txtinitials.text, titleid = int.parse(cbotitle.selectedvalue), fullnames = txtfullnames.text, surname = txtsurname.text, age = int.parse(txtage.text), dateofbirth = convert.todatetime(txtdateofbirth.text), passportnumber = txtpassport.text, areyouemployed = bool.parse(viewstate["areyouemployed"].tostring()), employer = txtemployer.text, contactnumber = txtcontactnumber.text, othercontanctnumber = txtothercontanctnumber.text, emailaddress = txtemailaddress.text, issacitizen = bool.parse(viewstate["issacitizen"].tostring()), telephonework = txttelephonework.text, telephonehome = txttelephonehome.text, }; _dc.legal_members.insertonsubmit(_legalmember); _dc.submitchanges();
sql table
create table [dbo].[legal_member]( [legalmembershipid] [int] identity(1,1) not null, [inceptiondate] [datetime] null, [legalpreferedname] [nvarchar](50) null, [initials] [nvarchar](50) null, [titleid] [int] null, [fullnames] [nvarchar](50) null, [surname] [nvarchar](50) null, [age] [int] null, [dateofbirth] [datetime] null, [idnumber] [nvarchar](50) null, [passportnumber] [nvarchar](50) null, [areyouemployed] [bit] null, [employer] [nvarchar](50) null, [contactnumber] [nvarchar](50) null, [othercontanctnumber] [nvarchar](50) null, [emailaddress] [nvarchar](50) null, [issacitizen] [bit] null, [telephonework] [nvarchar](50) null, [telephonehome] [nvarchar](50) null)
i don't think need line: try insert after removing line:
legalmembershipid = int.parse(txtmembershipnumber.text)
as primary key field auto increment. please remove , try insert.
Comments
Post a Comment