---
title: "where to add connection string of SQL server in asp.net page"  
description: "where to add connection string of SQL server in asp.net page"  
author: "Mark Devid"  
published: 2013-05-03  
updated: 2013-05-03  
canonical: https://www.mindstick.com/forum/799/where-to-add-connection-string-of-sql-server-in-asp-dot-net-page  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# where to add connection string of SQL server in asp.net page

Hi All!\
I am having an ASP.NET page that is containing the textboxes namely [username and password](https://www.mindstick.com/forum/160407/how-does-a-bearer-token-differ-from-other-authentication-methods-such-as-username-and-password) and a button named cmdlogin. I want that when I enter the data in [text boxes](https://www.mindstick.com/forum/34261/how-to-split-data-to-text-boxes-when-read-qr-code-data) \
then that data should be saved into the database.\
In [SQL server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) of [Visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available), I have created table and even also have given the\
INSERT INTO cmd_login VALUES(".......").Now the problem is when I entered the data in textbooxes it is not saved in the [database table](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table). what can I do.\
I have put my [connection string](https://www.mindstick.com/articles/328/connection-strings) into the [class file](https://www.mindstick.com/forum/60/how-we-add-dll-with-other-class-file). Do I need to put my connection string in the [web.config](https://www.mindstick.com/forum/183/web-config-file)?\
**my code is**\

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient;public class Db{    public static SqlConnection GetConnection()    {        SqlConnection cn = new SqlConnection();        cn.ConnectionString =@"Data                 Source=.\SQLEXPRESS;AttachDbFilename=E:\talat\MyRealSacaProject\App_Data\SACALogin.mdf;Inte    grated Security=True;User Instance=True;";        cn.Open();        return cn;    }    public static void SaveAdmin(admin a)    {        SqlConnection cn = GetConnection();        string sql = "INSERT INTO admin_login VALUES(@[User-Name],@Password)";        SqlCommand cmd = new SqlCommand(sql, cn);        cmd.Parameters.AddWithValue("@[User-Name]",a.username);        cmd.Parameters.AddWithValue("@Password", a.password);        cmd.ExecuteNonQuery();        cn.Close();    }    }
```

\
Thanks in advance! \

## Replies

### Reply by AVADHESH PATEL

Hi Mark!\
try this simple code:\
SqlConnection _conn = new SqlConnection(_connString);_conn.Open();SqlCommand _cmd = new SqlCommand();_cmd.CommandType = CommandType.StoredProcedure;_cmd.Parameters.Clear();_cmd.[Connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) = _conn;_cmd.CommandText = "INSERT INTO [tablename] VALUE ([fieldvalue])"; //here your textbox int _execute = _cmd.ExecuteNonQuery();\
bool _result = false;if(_execute != 1) _result = true;\
_conn.Close();\


---

Original Source: https://www.mindstick.com/forum/799/where-to-add-connection-string-of-sql-server-in-asp-dot-net-page

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
