TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bastola Kancha
NA
50
9.2k
sqlconnection problem
May 16 2016 2:08 AM
I have created a database file userData.mdf. And have a created a class named dbHelper. Here i have made three functions:
OpenConnection();
ExecuteQry();
CloseConnection();
The problem is here:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Insert_Delete_UpdateOperation
{
public class dbhelper
{
public static SqlConnection sqlConnection;
public static SqlDataReader sqlDataReader;
public static void OpenConnection()
{
String connectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename="c:\users\suraj\documents\visual studio 2012\Assignment\Insert,Delete,UpdateOperation\Insert,Delete,UpdateOperation\userData.mdf"; Integrated Security=True";);
sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
}
public static void ExecuteQry(string qry,Boolean state)
{
SqlCommand sqlcommand=new SqlCommand(qry,sqlConnection);
if(state)
{
sqlcommand.ExecuteNonQuery();
}
else
{
sqlDataReader=sqlcommand.ExecuteReader();
}
}
public static void CloseConnection()
{
if(sqlConnection.State==System.Data.ConnectionState.Open)
{
sqlConnection.Close();
}
}
}
}
Reply
Answers (
2
)
within table Insert data save in MVC 4 razor .
How to remove unused variable or object in class?