المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : adding data to database from combobox



C# Programming
02-01-2010, 01:21 AM
hi guys...i have a combobox on my form which is named as cmbfirma...and i fill it with a column of database..and i want user to add new firm if it doesnt exist in my database that is why i open new form and user writes new firm name to textbox and program writes new firm name to a txt file and i read it from there...and try to write that new form to my database..to do that i use code below
cmd.Parameters.AddWithValue("@firma",cmbFirma.SelectedItem.ToString());
but when i use it and check my database it writes there System.Data.DataRowView
and i tried another code below
cmd.Parameters.AddWithValue("@firma",cmbFirma.SelectedValue.ToString());
in that time it writes database normally only for the items which is listed in combobox and it gives error if i want to add the new firm name that i read from txt file...in error it says "Unable to set an object reference to an instance object"
what should i do to get rid off that errors ??
or should i use another database for my combobox ??
i use SqlExpress 2005 to create my database
thanks for your help