Database access [modified]
-
Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close(). public string constring = @" "; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select * from emp",con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); con.Close(); "Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this? -- modified at 18:59 Friday 9th February, 2007
-
Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close(). public string constring = @" "; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select * from emp",con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); con.Close(); "Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this? -- modified at 18:59 Friday 9th February, 2007
This should be posted in the SQL Database section.
_____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe
-
Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close(). public string constring = @" "; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select * from emp",con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); con.Close(); "Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this? -- modified at 18:59 Friday 9th February, 2007
sreecahitu wrote:
new SqlConnection(" ");
How is that a connection string ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
sreecahitu wrote:
new SqlConnection(" ");
How is that a connection string ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
I indicated the connection string correctly with source,user name and pwd, but i didnt mention here. string constring=@"source, user="",password="" "; SQLConnection con=new SqlConnection("cosnstring");
-
I indicated the connection string correctly with source,user name and pwd, but i didnt mention here. string constring=@"source, user="",password="" "; SQLConnection con=new SqlConnection("cosnstring");
OK, I think we've found the problem.
sreecahitu wrote:
string constring=@"source, user="",password="" ";
When you use @, you need two " to make *one* quote. So, it's user=""name""
sreecahitu wrote:
SQLConnection con=new SqlConnection("cosnstring");
Because you put it in quotes, you're passing in the value cosnstring, instead of the value of the variable with that name.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
OK, I think we've found the problem.
sreecahitu wrote:
string constring=@"source, user="",password="" ";
When you use @, you need two " to make *one* quote. So, it's user=""name""
sreecahitu wrote:
SQLConnection con=new SqlConnection("cosnstring");
Because you put it in quotes, you're passing in the value cosnstring, instead of the value of the variable with that name.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.
-
If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.
This may seem like a stupid question, but which database engine are you using? SQL Server, MySQL, Access, Oracle, ... ? You can find the correct format for your connection string at http://www.connectionstrings.com[^].
Dave Kreskowiak Microsoft MVP - Visual Basic
-
If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.
That doesn't look like a valid connection string to me. Did you post the actual code in the first instance ? Or did you change it in other ways ? This does not account for your actual error, really, which makes no sense to me, right now.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
That doesn't look like a valid connection string to me. Did you post the actual code in the first instance ? Or did you change it in other ways ? This does not account for your actual error, really, which makes no sense to me, right now.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
ya, thank you all, i modified wrongly. I got the problem, the problem is with declaring the declaration of string.
-
If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.