473,854 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

connect to sql server 2005 using c#

44 New Member
I need to connect to sql server 2005 from c# program, so that i can store the output of the c# code into the database.

Firstly i should get connected to the sql server, secondly i should create a sql table using c# program and then finally store the output of the c# program in the sql table.

please help me in this regard.
Sep 11 '07 #1
4 30733
k3nTm
9 New Member
I need to connect to sql server 2005 from c# program, so that i can store the output of the c# code into the database.

Firstly i should get connected to the sql server, secondly i should create a sql table using c# program and then finally store the output of the c# program in the sql table.

please help me in this regard.

HALO GOOD DAY

for your connection string use this code:

string ConnStrng = "Data Source=localhos t\\sqlexpress;I nitial Catalog=XXXXt; Integrated Security=SSPI;" ;

where: XXX is the name of your database.
Sep 11 '07 #2
pugalenthi
44 New Member
HALO GOOD DAY

for your connection string use this code:

string ConnStrng = "Data Source=localhos t\\sqlexpress;I nitial Catalog=XXXXt; Integrated Security=SSPI;" ;

where: XXX is the name of your database.
I have established the connection with SQL Server 2005 from my c# program. I am able to view the data in the tables using the SqlDataReader but how can i write into the database tables the output of my c# program. There isn't any class called SqlDataWriter. Please help me in this regard.
Sep 11 '07 #3
Plater
7,872 Recognized Expert Expert
You would use SQL statements.
Check this article:
http://www.thescripts.com/forum/thread635615.html
Sep 11 '07 #4
k3nTm
9 New Member
just try this code

string ConnStrng = "Data Source=localhos t\\sqlexpress;I nitial Catalog=Members Account; Integrated Security=SSPI;" ;
string updateRec = "INSERT INTO TblMembers(Full Name, Iam, Email, Password, BirthMonth, BirthDay, BirthYear) VALUES (@FullName, @Iam, @Email, @Password, @BirthMonth, @BirthDay, @BirthYear)";

SqlConnection SqlConn = new SqlConnection(C onnStrng);

SqlCommand sqlCmd = new SqlCommand(upda teRec,SqlConn);

sqlCmd.Paramete rs.AddWithValue ("@FullName" , txtfullname.Tex t);
sqlCmd.Paramete rs.AddWithValue ("@Iam", txtiam.Text);
sqlCmd.Paramete rs.AddWithValue ("@Email", txtemail.Text);
sqlCmd.Paramete rs.AddWithValue ("@Password" , txtpassword.Tex t);
sqlCmd.Paramete rs.AddWithValue ("@BirthMont h", ddlmonth.Text);
sqlCmd.Paramete rs.AddWithValue ("@BirthDay" , ddlday.Text);
sqlCmd.Paramete rs.AddWithValue ("@BirthYear ", txtyear.Text);

if (Page.IsValid)
{
try
{
SqlConn.Open();
sqlCmd.ExecuteN onQuery();
lblSecMessage.T ext = "Thank you for registering.";
}
catch (Exception ex)
{
lblSecMessage.T ext = ex.Message;
}
finally
{
SqlConn.Close() ;
}
}
Sep 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4087
by: Wade | last post by:
Is it possible to connect to a SQL 2005 Express db using Visual Basic 2005 Express? I cannot get past the connection.open statement without the error "...Version=2.0.0.0; SqlClient.SqlClientPermissions; PublicKeyToken=b77a5c561934e089 failed." I have WinXP, SQL Express 2005, and VB 2005 Express all on same machine. I've found hundreds of samples and tried most of them, but still get same error.
14
7051
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that sql server resides on is not reachable. The error is different depending on the connection string that I use. If I use the following connection string: "server=192.1.1.1; Initial Catalog=master; uid=The_User; password=The_Password; Connect...
0
2621
by: Larry Rebich | last post by:
I am trying to use the sample web template that is distributed with Visual Studio 2005 called 'Personal Web Site Starter Kit'. After running for awhile it fails with the following message: ------------------------------------------ Server Error in '/PersonalWebSiteStarter' Application. -------------------------------------------------------------------------------- An error has occurred while establishing a connection to the server. ...
13
2124
by: josh | last post by:
I'm pretty new to both sql 2005 and VB but please bear with me. I have installed SQL 2005 express on a Windows 2003 Standard server. I have also installed VB 2005 Express edition on the server. SQL seems to be running fine (I can create databases, tables, modify them, etc.) I have created a very basic app in VB express that just lets me view and modify the current tables. It works just fine on the server. However, I am trying to make...
9
2626
by: Gabriel | last post by:
Hello, I installed SQL server 2005 SP1 on a Windows XP SP2 From Visual Studio, I'm trygin to create a connection to a database, but I receive this error but I'm creating the connection (I don't receive the database list in the dropdown) "An error has occured while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that
0
4892
by: tamayi | last post by:
I have a problem (like most others posting issues on this forum :) ) I have a remote server running Windows XP SP2, with both SQL Server 2005 Express with Advanced Features and SQL 2000 installed. I can remotely connect to the SQL Server 2000 instance using Query Analyser or Enterprise Manager. I can also remotely connect to the SQLEXPRESS using Management Studio Express Edition. I am writing an ASP.NET 2.0 with VS2005 application...
6
9216
by: Zvonko Bi¹kup | last post by:
Hi! I am trying to connect to my SqlServer 2005 thru internet, but it is not working. I have a dyndns updater on my server which tells me an ip address of the router. The router is configured to forward TCP port 1433 to LAN IP address of the computer on which is SQL Server installation. What is the connection string to connect to my server. I tried xxx.dyndns.org:1433, but it doesn't work. There is a default instance installed on that...
5
2550
by: Alan Silver | last post by:
Hello, Server configuration: Windows 2003 Server SP2 SQL Server 2000 SP4 ..NET v2.0.50727 just built up a new server using the same configuration as my current one. I even used the same CDs and registration keys, so I'm certain that the two machines are as similar as they can be.
8
2843
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is put into stand-by or hibernation 3. later, computer is brought out of stand-by or hibernation 4. when trying to save or close form, SQL exception comes up (remote system closed conn) I know this relates to connection pooling, but I am having a...
7
5952
by: RN1 | last post by:
Is it possible to connect to my local SQL Server 2005 database from a remote web server? If yes, what ConnectionString do I use? Thanks, Ron
0
9903
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10766
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10373
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7083
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5753
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5946
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.