943,744 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 297103
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jan 8th, 2009
-1

Re: How do you connect to a sql database using C#

how do you connect to a Excel database using c#
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mr.mukesh is offline Offline
2 posts
since Jan 2009
Jan 8th, 2009
0

Re: How do you connect to a sql database using C#

Hmmm, perhaps I'm mistaken but there are no 'Excel databases.' I think you simply wish to read from an Excel file > that is, a spreadsheet. In which case, there are probably (or rather must be) API's out there and a Google search will definitely aid you in that.

Or perhaps you mean to access a Microsoft Access database?
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Nov 21st, 2009
0
Re: How do you connect to a sql database using C#
can we use dataset in console mode and how
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kunalsingh4u is offline Offline
1 posts
since Nov 2009
Nov 22nd, 2009
0
Re: How do you connect to a sql database using C#
Click to Expand / Collapse  Quote originally posted by mr.mukesh ...
how do you connect to a Excel database using c#
You can use one of the Microsoft database connectors, if you have it installed, some may be provided by installing Office or other products. Your DSN string will be something like:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";

at least, if you are using the Jet OLEDB type connection. There are others, see http://www.connectionstrings.com/ for better informed examples.

This will allow you to access a table within a worksheet, the HDR=Yes tells it to expect a row of column names at the top, you have to handle the data types yourself, I think. I have working code examples at work someplace but nothing available here.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
LesF is offline Offline
9 posts
since May 2009
Jul 17th, 2010
0

Debug Error

C# Syntax (Toggle Plain Text)
  1. OleDbConnection con = new OleDbConnection (@"Network Library=DBMSSOCN;Data Source=10.16.132.1;database=craccount;User id=rameshc;Password=;Vishnu10");
  2. con.Open();
  3. int a, j;
  4. string gender;
  5. a = int.Parse(textBox8.Text);
  6. if ( radioButton1 .Checked == true )
  7. gender = "male";
  8. else
  9. gender = "female";
  10. MessageBox.Show(a.ToString());
  11. if (a > 1000)
  12. {
  13. OleDbCommand cmd = new OleDbCommand ("select *from bankinfo,con");
  14. cmd.CommandType = CommandType.Text;
  15. cmd.CommandText = "insert into account values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + gender + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')";
  16. j = cmd.ExecuteNonQuery();
  17. con.Close();
  18. }
  19. else
  20. {
  21. MessageBox.Show("No Sufficent data");
  22. }
Last edited by adatapost; Dec 4th, 2010 at 4:31 am. Reason: Added [code] tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rameshcpr is offline Offline
1 posts
since Jul 2010
Jul 17th, 2010
0
Re: How do you connect to a sql database using C#
you can use this statement to connect with sql

C# Syntax (Toggle Plain Text)
  1. string str = MyProject.Properties.Settings.Default.dbnameConnectionString;
  2. sqlconnection conn=new sqlconnection(str);
Last edited by adatapost; Dec 4th, 2010 at 4:31 am. Reason: Added [code] tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karez is offline Offline
1 posts
since Jul 2010
Jul 17th, 2010
0
Re: How do you connect to a sql database using C#
Even I have a doubt on @"Network Library=DBMSSOCN..? also, what is 'Persist info', that is in connection string...
Last edited by arunkumars; Jul 17th, 2010 at 1:21 pm.
Reputation Points: 26
Solved Threads: 19
Junior Poster
arunkumars is offline Offline
166 posts
since Jul 2009
Jul 27th, 2010
0
Re: How do you connect to a sql database using C#
C# Syntax (Toggle Plain Text)
  1. class sqlconnection
  2. {
  3. SqlConnection myconcection;
  4.  
  5.  
  6. private void getConnection()
  7. {
  8. String connstring = "";//your connection string
  9. SqlConnection myconcection = new SqlConnection(connstring);
  10. }
  11.  
  12.  
  13. // method to get data
  14. public DataSet getData(String sql)
  15. {
  16. getConnection();
  17.  
  18. SqlDataAdapter adptre = new SqlDataAdapter();
  19. DataSet resultSet = new DataSet();
  20.  
  21. SqlCommand sqlcmd = new SqlCommand(sql, myconcection);
  22. adptre.SelectCommand = sqlcmd;
  23. myconcection.Open();
  24. try
  25. {
  26. adptre.Fill(resultSet);
  27. }
  28.  
  29. catch(Exception ex)
  30. {
  31.  
  32. }
  33. myconcection.Close();
  34. return resultSet;
  35. }
  36. // method to add data
  37. public void setData(string sqlcmd)
  38. {
  39. getConnection();
  40. myconcection.Open();
  41.  
  42. string sqlcommand = sqlcmd;
  43. SqlCommand cmd = new SqlCommand(sqlcommand, myconcection);
  44. cmd.ExecuteNonQuery();
  45. myconcection.Close();
  46. }
  47.  
  48. }
Last edited by adatapost; Dec 4th, 2010 at 4:32 am. Reason: Added [code] tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
priya2010 is offline Offline
1 posts
since Jul 2010
Aug 26th, 2010
0
Re: How do you connect to a sql database using C#
How to connect a form to a sql server database from C# to ado.net. Please help me
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anitha10 is offline Offline
19 posts
since Aug 2010
Aug 27th, 2010
0
Re: How do you connect to a sql database using C#
please help me out to connect oracle database in c# a complete example program is needed! please help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ajnabidost is offline Offline
1 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C# Forum Timeline: how to connect the module with the code in a project in C #
Next Thread in C# Forum Timeline: COM Add-in for office, install problem.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC