| | |
error on sqlserver database connection please rectify that
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 19
Reputation:
Solved Threads: 0
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static SqlConnection cn = new SqlConnection("userid=sa;password=;database=northwind;server=localhost"); SqlCommand cmd = new SqlCommand("select * from kkr", cn); SqlDataReader dr; private void button1_Click(object sender, EventArgs e) { if (cn.State = ConnectionState.Closed) { cn.Open(); MessageBox.Show("ok"); dr = cmd.ExecuteReader(); label1.Text = dr.GetName(0); label2.Text = dr.GetName(1); label3.Text = dr.GetName(2); } else MessageBox.Show("connection is already opened:"); } private void button2_Click(object sender, EventArgs e) { if(dr.Read()==true) { textBox1.Text = dr[0].ToString(); textBox2.Text = dr[1].ToString(); textBox3.Text = dr[2].ToString(); } else { MessageBox.Show("No MOre Records:"); } } private void label1_Click(object sender, EventArgs e) { } } }
Hai to All,
i written a code on c# dotnet using the sqlserver but it gives a error like that following
"Error 1 Property or indexer 'System.Data.Common.DbConnection.State' cannot be assigned to -- it is read only C:\examplesC#\WindowsApplication1\WindowsApplication1\Form1.cs 24 17 WindowsApplication1
Error 2 Cannot implicitly convert type 'System.Data.ConnectionState' to 'bool' C:\examplesC#\WindowsApplication1\WindowsApplication1\Form1.cs 24 17 WindowsApplication1
"
please recify my problem
A.kranti kumar
Last edited by Ancient Dragon; Nov 11th, 2008 at 7:58 am. Reason: add code tags
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
If you looked at the line of code its complaining about, its very true.
Your code is incorrect - please use code tags next time.
C# Syntax (Toggle Plain Text)
if (cn.State = ConnectionState.Closed)
Your code is incorrect - please use code tags next time.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 138
lol yes get your equals symbols in order
you are try to check its state, not set it
you are try to check its state, not set it
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
yes the guys are Right, it must look like this
Thanks
C# Syntax (Toggle Plain Text)
if (cn.State == ConnectionState.Closed)
Thanks
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
![]() |
Other Threads in the C# Forum
- Previous Thread: Problem in Connecting to the database
- Next Thread: How do I suspend control on one form until data is entered on another?
Views: 754 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development drawing encryption enum event excel file files form format ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






