manoj kumar

manoj kumar

  • NA
  • 147
  • 137.8k

Asp .Net

Dec 23 2009 3:00 AM
Hi I am using this code for insert data in sql..
code is correct.and data is also insert in database bt some field of Checkboxlist in
this form..chechboxlist record is not show in data base..checkboxlist columns show emthy in database...wt happen ...i dnt know pls help some one.......
  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Web;  
  5. using System.Web.Security;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. using System.Web.UI.WebControls.WebParts;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Data.SqlClient;  
  11. using System.Data.SqlTypes;  
  12. public partial class _Default : System.Web.UI.Page  
  13. {  
  14. string a;  
  15. string Strlist1 = "", Strlist2 = "", Strlist3 = "", Strlist4 = "", Strlist5 = "", Strlist6 = "", Strlist7 = "";  
  16. protected void Page_Load(object sender, EventArgs e)  
  17. {  
  18. string database = ConfigurationManager.ConnectionStrings["manoj"].ConnectionString;  
  19. SqlConnection con = new SqlConnection(database);  
  20. SqlDataAdapter da = new SqlDataAdapter("select Industry,EFairs,School,PendingSchool,DisplayTextLink,Permission,Flags from Master_EditEmp", con);  
  21. DataSet ds = new DataSet();  
  22. da.Fill(ds, "table");  
  23. CheckBoxList1.DataSource = ds.Tables[0];  
  24. CheckBoxList1.DataTextField = ds.Tables[0].Columns["Industry"].ColumnName.ToString();  
  25. CheckBoxList1.DataValueField = ds.Tables[0].Columns["Industry"].ColumnName.ToString();  
  26. CheckBoxList1.DataBind();  
  27. chkEflair.DataSource = ds.Tables[0];  
  28. chkEflair.DataTextField = ds.Tables[0].Columns["EFairs"].ColumnName.ToString();  
  29. chkEflair.DataValueField = ds.Tables[0].Columns["EFairs"].ColumnName.ToString();  
  30. chkEflair.DataBind();  
  31. chkschool.DataSource = ds.Tables[0];  
  32. chkschool.DataTextField = ds.Tables[0].Columns["School"].ColumnName.ToString();  
  33. chkschool.DataValueField = ds.Tables[0].Columns["School"].ColumnName.ToString();  
  34. chkschool.DataBind();  
  35. chkpenschool.DataSource = ds.Tables[0];  
  36. chkpenschool.DataTextField = ds.Tables[0].Columns["PendingSchool"].ColumnName.ToString();  
  37. chkpenschool.DataValueField = ds.Tables[0].Columns["PendingSchool"].ColumnName.ToString();  
  38. chkpenschool.DataBind();  
  39. chkdisplay.DataSource = ds.Tables[0];  
  40. chkdisplay.DataTextField = ds.Tables[0].Columns["DisplayTextLink"].ColumnName.ToString();  
  41. chkdisplay.DataValueField = ds.Tables[0].Columns["DisplayTextLink"].ColumnName.ToString();  
  42. chkdisplay.DataBind();  
  43. chkpermission.DataSource = ds.Tables[0];  
  44. chkpermission.DataTextField = ds.Tables[0].Columns["Permission"].ColumnName.ToString();  
  45. chkpermission.DataValueField = ds.Tables[0].Columns["Permission"].ColumnName.ToString();  
  46. chkpermission.DataBind();  
  47. chkflags.DataSource = ds.Tables[0];  
  48. chkflags.DataTextField = ds.Tables[0].Columns["Flags"].ColumnName.ToString();  
  49. chkflags.DataValueField = ds.Tables[0].Columns["Flags"].ColumnName.ToString();  
  50. chkflags.DataBind();  
  51. if(rbstatus.Checked==true)  
  52. {  
  53. a="Disabled";  
  54. }  
  55. else if(rbstatus1.Checked==true)  
  56. {  
  57. a="Enabled";  
  58. }  
  59. }  
  60. private bool validate1()  
  61. {  
  62. int counter = 0;  
  63. foreach (ListItem li in CheckBoxList1.Items)  
  64. {  
  65. if (li.Selected)  
  66. {  
  67. counter = counter + 1;  
  68. Strlist1 = Strlist1 + " " + li.Text;  
  69. }  
  70. }  
  71. if (counter > 2)  
  72. {  
  73. return false;  
  74. }  
  75. else  
  76. {  
  77. return true;  
  78. }  
  79. }  
  80. private bool validate2()  
  81. {  
  82. int counter = 0;  
  83. foreach (ListItem li in chkEflair.Items)  
  84. {  
  85. if (li.Selected)  
  86. {  
  87. counter = counter + 1;  
  88. Strlist2 = Strlist2 + " " + li.Text;  
  89. }  
  90. }  
  91. if (counter > 2)  
  92. {  
  93. return false;  
  94. }  
  95. else  
  96. {  
  97. return true;  
  98. }  
  99. }  
  100. private bool validate3()  
  101. {  
  102. int counter = 0;  
  103. foreach (ListItem li in chkschool.Items)  
  104. {  
  105. if (li.Selected)  
  106. {  
  107. counter = counter + 1;  
  108. Strlist3 = Strlist3 + " " + li.Text;  
  109. }  
  110. }  
  111. if (counter > 2)  
  112. {  
  113. return false;  
  114. }  
  115. else  
  116. {  
  117. return true;  
  118. }  
  119. }  
  120. private bool validate4()  
  121. {  
  122. int counter = 0;  
  123. foreach (ListItem li in chkpenschool.Items)  
  124. {  
  125. if (li.Selected)  
  126. {  
  127. counter = counter + 1;  
  128. Strlist4 = Strlist4 + " " + li.Text;  
  129. }  
  130. }  
  131. if (counter > 2)  
  132. {  
  133. return false;  
  134. }  
  135. else  
  136. {  
  137. return true;  
  138. }  
  139. }  
  140. private bool validate5()  
  141. {  
  142. int counter = 0;  
  143. foreach (ListItem li in chkdisplay.Items)  
  144. {  
  145. if (li.Selected)  
  146. {  
  147. counter = counter + 1;  
  148. Strlist5 = Strlist5 + " " + li.Text;  
  149. }  
  150. }  
  151. if (counter > 2)  
  152. {  
  153. return false;  
  154. }  
  155. else  
  156. {  
  157. return true;  
  158. }  
  159. }  
  160. private bool validate6()  
  161. {  
  162. int counter = 0;  
  163. foreach (ListItem li in chkpermission.Items)  
  164. {  
  165. if (li.Selected)  
  166. {  
  167. counter = counter + 1;  
  168. Strlist6 = Strlist6 + " " + li.Text;  
  169. }  
  170. }  
  171. if (counter > 2)  
  172. {  
  173. return false;  
  174. }  
  175. else  
  176. {  
  177. return true;  
  178. }  
  179. }  
  180. private bool validate7()  
  181. {  
  182. int counter = 0;  
  183. foreach (ListItem li in chkflags.Items)  
  184. {  
  185. if (li.Selected)  
  186. {  
  187. counter = counter + 1;  
  188. Strlist7 = Strlist7 + " " + li.Text;  
  189. }  
  190. }  
  191. if (counter > 2)  
  192. {  
  193. return false;  
  194. }  
  195. else  
  196. {  
  197. return true;  
  198. }  
  199. }  
  200. private bool check()  
  201. {  
  202. if (validate1())  
  203. {  
  204. if (validate2())  
  205. {  
  206. if (validate3())  
  207. {  
  208. if (validate4())  
  209. {  
  210. if (validate5())  
  211. {  
  212. if (validate6())  
  213. {  
  214. if (validate7())  
  215. {  
  216. return true;  
  217. }  
  218. else  
  219. {  
  220. return false;  
  221. }  
  222. }  
  223. else  
  224. {  
  225. return false;  
  226. }  
  227. }  
  228. else  
  229. {  
  230. return false;  
  231. }  
  232. }  
  233. else  
  234. {  
  235. return false;  
  236. }  
  237. }  
  238. else  
  239. {  
  240. return false;  
  241. }  
  242. }  
  243. else  
  244. {  
  245. return false;  
  246. }  
  247. }  
  248. else  
  249. {  
  250. return false;  
  251. }  
  252. }  
  253. protected void btnsave_Click(object sender, EventArgs e)  
  254. {  
  255. if (check())  
  256. {  
  257. string data = ConfigurationManager.ConnectionStrings["manoj"].ConnectionString;  
  258. SqlConnection con = new SqlConnection(data);  
  259. SqlCommand cmd = new SqlCommand();  
  260. cmd.CommandType = CommandType.StoredProcedure;  
  261. cmd.CommandText = "Edit";  
  262. cmd.Parameters.Add("@AccountManager", SqlDbType.VarChar).Value = txtaccountmgr.Text;  
  263. cmd.Parameters.Add("@AccountManagerContact", SqlDbType.VarChar).Value = txtmgrcontact;  
  264. cmd.Parameters.Add("@Remarks", SqlDbType.VarChar).Value = txtremarks.Text;  
  265. cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar).Value = txtcompany.Text;  
  266. cmd.Parameters.Add("@ShortName", SqlDbType.VarChar).Value = txtshortname.Text;  
  267. cmd.Parameters.Add("@BusinessRegNo", SqlDbType.VarChar).Value = txtbusiness.Text;  
  268. cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = txtdes.Text;  
  269. cmd.Parameters.Add("@Industry", SqlDbType.VarChar).Value = Strlist1;  
  270. cmd.Parameters.Add("@ContactPerson", SqlDbType.VarChar).Value = txtconperson.Text;  
  271. cmd.Parameters.Add("@Tel", SqlDbType.Int).Value = txttel.Text;  
  272. cmd.Parameters.Add("@Fax", SqlDbType.Int).Value = txtfax.Text;  
  273. cmd.Parameters.Add("@Website", SqlDbType.VarChar).Value = txtweb.Text;  
  274. cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = txtemail.Text;  
  275. cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtpass.Text;  
  276. cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtadd.Text;  
  277. cmd.Parameters.Add("@EFairs", SqlDbType.VarChar).Value = Strlist2;  
  278. cmd.Parameters.Add("@School", SqlDbType.VarChar).Value = Strlist3;  
  279. cmd.Parameters.Add("@PendingSchools", SqlDbType.VarChar).Value = Strlist4;  
  280. cmd.Parameters.Add("@DisplayTextLink", SqlDbType.VarChar).Value = Strlist5;  
  281. cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = a;  
  282. cmd.Parameters.Add("@Permission", SqlDbType.VarChar).Value = Strlist6;  
  283. cmd.Parameters.Add("@Flags", SqlDbType.VarChar).Value = Strlist7;  
  284. cmd.Parameters.Add("@Designation", SqlDbType.VarChar).Value = txtdesig.Text;  
  285. cmd.Connection = con;  
  286. try  
  287. {  
  288. con.Open();  
  289. cmd.ExecuteNonQuery();  
  290. Response.Write(true);  
  291. }  
  292. catch (Exception ex)  
  293. {  
  294. throw ex;  
  295. }  
  296. finally  
  297. {  
  298. con.Close();  
  299. }  
  300. }  
  301. }  
  302. }  

Attachment: New Folder.rar

Answers (7)