[問題]資料庫新手(已爬文)

看板C_Sharp作者 (昨天似乎有)時間15年前 (2010/10/05 18:51), 編輯推噓1(104)
留言5則, 4人參與, 最新討論串1/1
今天依照範例, 在連接資料庫與c#, 不過不能run, 他是顯示遺漏偵錯目標 請建置專案後重試, 不過我連建置都不能建置, 所以想請問一下各位大大我的問題在哪裡ㄚ= =" 萬分感激<(_ _)> 隨文附上程式碼 using System.Data.SqlClient; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string connStr,selectCmd; connStr = "Server=localhost;dataDB;uid=sa;pwd=123456;"; SqlConnection myConnection = new SqlConnection(connStr); selectCmd = "SELECT * FROM MEMBER"; SqlConnection conn; SqlCommand cmd; SqlDataReader reader; conn = new SqlConnection(connStr); conn.Open(); cmd = new SqlCommand(selectCmd, conn); reader = cmd ExecuteReader(); for (int i = 0; i < reader.FieldCount; i++) { richTextBox1.Text += reader.GetName(i) + "\t"; } richTextBox1.Text +="\n\n"; while (reader.Read()) { for(int j = 0; j < reader.FieldCount; j++) { richTextBox1.Text += reader[j] + "\t"; } richTextBox1.Text += "\n"; } reader.Close(); conn.Close(); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.124.43.58

10/05 20:13, , 1F
連線字串有錯.
10/05 20:13, 1F

10/06 02:06, , 2F
string->String ?
10/06 02:06, 2F

10/06 07:55, , 3F
datadb應該是data source=xxx
10/06 07:55, 3F

10/06 15:25, , 4F
Data Source=(local);Initial Catalog=dataDB;User ID=sa;P
10/06 15:25, 4F

10/06 15:26, , 5F
assword=123456
10/06 15:26, 5F
文章代碼(AID): #1CgmCQA_ (C_Sharp)