簡單的控制台學習資料,SQL查詢器

2021-06-16 05:29:21 字數 3288 閱讀 1508

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.data;

using system.data.sqlclient;

using system.diagnostics;

namespace sql查詢器

class program

private static string servername = "";

private static string logindatabasename = "";

private static string loginusername = "";

private static string loginpwd = "";

private static sqlconnection connect = null;

static void main(string args)

console.title = "sql簡單查詢器";

servername = init("伺服器位址");

logindatabasename = init("服務庫名稱");

loginusername = init("登陸使用者名稱");

loginpwd = init("登陸使用者口令");

openconnect();            

static void executesql()

goto sql;

sql:

console.write("sql:");

string value = console.readline();

if (value == null || value.trim() == "")

goto sql;

trystopwatch watch = new stopwatch();

watch.start();

datetime begintime = datetime.now;

sqlcommand cmd = new sqlcommand(value, connect);

sqldataadapter da = new sqldataadapter(cmd);

datatable sqltable = new datatable();

da.fill(sqltable);

watch.stop();

console.writeline("總共耗時:" + watch.elapsed.tostring() + " 記錄條數:" + sqltable.rows.count);

stringbuilder cols = new stringbuilder();

for (int c = 0; c < sqltable.columns.count; c++)

console.writeline(cols.tostring().trim());

for (int r = 0; r < sqltable.rows.count; r++)

stringbuilder rows = new stringbuilder();

for (int c = 0; c < sqltable.columns.count; c++)

if (sqltable.rows[r][c] != dbnull.value)

else

console.writeline(rows.tostring().trim());

console.writeline("");

goto sql;

catch (exception e)

console.writeline(e.message);

goto sql;

static void openconnect()

if (servername == null || servername.trim() == "")

servername = init("伺服器位址");

if (logindatabasename == null || logindatabasename.trim() == "")

logindatabasename = init("伺服器位址");

string strconnect = "data source=" + servername + ";initial catalog=" + logindatabasename + ";user id=" + loginusername + ";password=" + loginpwd + ";integrated security=false;connect timeout=15;";

if (connect == null)

connect = new sqlconnection(strconnect);

if (connect.state != connectionstate.closed)

tryconnect.close();

catch

connect.connectionstring = strconnect;

tryconsole.writeline("正在連線資料伺服器,請候候...");

connect.open();

console.clear();

executesql();

catch (exception e)

console.writeline(e.message);

if (e.message.contains("provider: named pipes provider, error: 40") == true)

servername = init("伺服器位址");

logindatabasename = init("伺服器位址");

loginusername = init("登陸使用者名稱");

loginpwd = init("登陸使用者口令");

openconnect();

static string init(string name)

goto config;

config:

console.write(name + ":");

string value = console.readline();

if (value == null || value.trim() == "")

console.writeline(name + "不能為空,請重新輸入!");

goto config;

return value;

沒有控制台視窗的控制台程式

include include pragma comment linker,subsystem windows entry maincrtstartup int main int argc,char argv 編譯後執行程式會彈出乙個訊息框,而沒有背後的控制台視窗。再看看下面的 include in...

mysql資料庫控制台 mysql 控制台操作

其實mysql的對資料庫的操作與其它的sql類資料庫大同小異,您最好找本將sql的書看看。一 連線mysql資料庫 1.首先開啟cmd進入dos視窗 2.切換至目錄 d mysql5.0 mysql 5.0.51b win32 bin 即 mysql安裝目錄下面的bin目錄,該目錄內有很多exe執行...

網管控制台學習筆記

1.注意include路徑設定,由於 裡面是 include 所以只需要包含到g svn winutils library snmp include 而不要到g svn winutils library snmp include snmp pp,這樣就錯了 2.儲存list control裡面的內容...