作者FUDIRTY (昨天似乎有)
看板C_Sharp
标题[问题]资料库新手(已爬文)
时间Tue Oct 5 18:51:03 2010
今天依照范例,
在连接资料库与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
1F:推 horngsh:连线字串有错. 10/05 20:13
2F:→ tedcat:string->String ? 10/06 02:06
3F:→ chancewen:datadb应该是data source=xxx 10/06 07:55
4F:→ iiscon:Data Source=(local);Initial Catalog=dataDB;User ID=sa;P 10/06 15:25
5F:→ iiscon:assword=123456 10/06 15:26