Hi
I want to declare a coonectionstring in winapps as declared in web.config file in webapps.
I declare that in app.config as follows -
<connectionStrings>
-
<add name="ABC_Enterprises_.Properties.Settings.ABCEnterpriseDataConnectionString"
-
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ABCEnterpriseData.mdf;Integrated Security=True;User Instance=True"
-
providerName="System.Data.SqlClient" />
-
</connectionStrings>
-
but now i dnt know how to call this in program.
Can you please help me
Thanks
1 1171
hello
I am using sql for the first time with dotnet.
I had created the database and directly using .net by choosing sqldatabase from new item
and in the form i write the following code. My code is : -
string constr = ConfigurationSettings.AppSettings["ConnectionString1"];
-
SqlConnection conn = new SqlConnection(constr);
-
conn.Open();
-
SqlCommand cmd = new SqlCommand();
-
string str = "insert into OwnerDetails(OwnerId,FirstName,MiddleName,LastName,Age,Occupation,Address,City,State,PinCode,TelNo,Others) values(1,@FirstName,@MiddleName,@LastName,@Age,@Occupation,@Address,@City,@State,@PinCode,@TelNo,@Others)";
-
cmd.Connection = conn;
-
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text;
-
cmd.Parameters.Add("@MiddleName", SqlDbType.VarChar).Value = txtMName.Text;
-
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;
-
cmd.Parameters.Add("@Age", SqlDbType.Int).Value = txtAge.Text;
-
cmd.Parameters.Add("@Occupation", SqlDbType.VarChar).Value = txtOccupation.Text;
-
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtAddress.Text;
-
cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = cmbCity.SelectedItem.ToString();
-
cmd.Parameters.Add("@State", SqlDbType.VarChar).Value = cmbState.SelectedItem.ToString();
-
cmd.Parameters.Add("@PinCode", SqlDbType.VarChar).Value = txtPincode.Text;
-
cmd.Parameters.Add("@TelNo", SqlDbType.VarChar).Value = txtTelNo.Text;
-
cmd.Parameters.Add("@Others", SqlDbType.VarChar).Value = txtOthers.Text;
-
-
cmd.CommandText = str;
-
cmd.CommandType = CommandType.Text;
-
cmd.ExecuteNonQuery();
-
conn.Close();
-
-
App.config files setting:
-
<add name="ConnectionString1"
-
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NGEnterpriseData.mdf;Integrated Security=True;User Instance=True"
-
providerName="System.Data.SqlClient" />
-
-
But after when i ran the application i got the following error
The ConnectionString property has not been initialsed
Please suggest me why this error occurs and can i modify it
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dotnetified |
last post by:
Reposting after about 2 weeks of no response ... thanks if you can help...
----------------------------------------------------------------------------
--------------
To anyone who thinks they...
|
by: Tony |
last post by:
Dear All,
When I run an example program on the
http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3
...
|
by: Alixx Skevington |
last post by:
OK why does the following code work in a Windows form with a crystal report
viewer but not in a webform. I get the usual
CrystalReports.EngineLogONException logon Failed when this is called in...
|
by: Sam |
last post by:
I'm trying to create authentication for username and password but encounter
below error message:
Error Message
-----------------------
The ConnectionString property has not been initialized....
|
by: John Wilhelm |
last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node
from my app.config file the node come back with "nothing". The xmldocment
loads OK, but I can't retrive a node. The...
|
by: manicmax |
last post by:
Hey I have a question for u
I am taking connection string from IIS like this
readonly string dataSource3 =ConfigurationManager.ConnectionStrings.ConnectionString;
and using this dataSource3 ...
|
by: TG |
last post by:
Hi!
Once again I have hit a brick wall here. I have a combobox in which
the user types the server name and then clicks on button 'CONNECT' to
populate the next combobox which contains all the...
|
by: aboutjav.com |
last post by:
Hi,
I need some help. I am getting this error after I complete the asp.net
register control and click on the continue button. It crashed when it
tries to get
it calls this Profile property
...
|
by: Andrew Cooper |
last post by:
Greetings,
I've got a website that has several pages with DataGrid controls on
them. The controls are bound to Object Datasources. On one of the
pages I keep getting a "Timeout expired. The...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |