因為學弟阿帕...........找到了想當年的專題程式= =
這個是我寫的資料庫連線物件~~~~記得是我寫的吧XD
myConnection.ConnectionString = @"Data Source=163.18.22.142;Initial Catalog=msngps;Persist Security Info=True;User ID=sa;Password=8051";
這段程式是資料庫的連線字串~~~~~
我的設定是
連線163.18.22.142
資料庫msngps
帳號sa
密碼8051
用法.........總覺得好鳥.........因為還要另外創SqlDataReader ..........= =
------------------------------------------------------------------------------------
MyDB mydb = new MyDB();
mydb.Query(sql);
SqlDataReader myReader = mydb.DbFetchArray();
string latitude = "";
string longitude = "";
while (myReader.Read())
{
latitude = myReader.GetString(0);
longitude = myReader.GetString(1);
}
------------------------------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class MyDB
{
private SqlConnection myConnection = new SqlConnection();
private SqlCommand myCommand;
public MyDB()
{
myConnection.ConnectionString = @"Data Source=163.18.22.142;Initial Catalog=msngps;Persist Security Info=True;User ID=sa;Password=8051";
myConnection.Open();
}
public void query(string sql)
{
myCommand = new SqlCommand(sql, myConnection);
}
public void executeReader()
{
myCommand.ExecuteReader();
}
public SqlDataReader dbFetchArray()
{
return myCommand.ExecuteReader();
}
public void closeConnect()
{
myConnection.Close();
}
public bool hasRows()
{
SqlDataReader dr = this.dbFetchArray();
if (dr.HasRows)
{
return true;
}
else
{
return false;
}
}
public void closeDB()
{
myConnection.Close();
}
}
訂閱:
發佈留言 (Atom)
沒有留言:
發佈留言