Hello There
I am just learning user Control in Visual Studio 2015. Everything was going fine but when i tried to access the database in user control file i am getting null error
the same connection string is working fine in winform but not working in usercontrol the error comming when I am trying to drag the user control page to my winform. the image of error is attached
my app.config code is written here
app.config
- "1.0" encoding="utf-8" ?>
-
-
-
"CC" connectionString="Data Source=DESKTOP-M5IBRH0\sqlexpress;Initial Catalog=RMS;Integrated Security=True" providerName="System.Data.SqlClient"/> -
-
"v4.0" sku=".NETFramework,Version=v4.5.2" />
Code of User Control:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using System.Configuration;
- namespace usercontrol_with_sqlconnection
- {
- public partial class user_A : UserControl
- {
- public static string constring = ConfigurationManager.ConnectionStrings["CC"].ConnectionString;
- SqlConnection con = new SqlConnection(constring);
- public user_A()
- {
- InitializeComponent();
- }
- }
- }

Jignesh KumarPosted Apr 23, 2020, 6:01 AM
praveen mauryaPosted Apr 23, 2020, 6:58 AM
Rajanikant HawaldarPosted Apr 23, 2020, 4:44 AM