DataPlatformDevelopmentForums>ADO.NETDataSet上有一篇問答講的很好這是她的網(wǎng)址http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/1faff35e-055b-4728-a6c8-ece257585ab7在我們平時(shí)的簡(jiǎn)單應(yīng)用中,或者是剛開始學(xué)習(xí)使用ADO.NET,用基于服務(wù)的數(shù)據(jù)庫會(huì)方便一些,但也" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

C# 使用基于服務(wù)的數(shù)據(jù)庫的使用注意

系統(tǒng) 2196 0

Data Developer Center > Data Platform Development Forums > ADO.NET DataSet 上有一篇問答講的很好

這是她的網(wǎng)址 http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/1faff35e-055b-4728-a6c8-ece257585ab7

在我們平時(shí)的簡(jiǎn)單應(yīng)用中,或者是剛開始學(xué)習(xí)使用ADO.NET,用基于服務(wù)的數(shù)據(jù)庫會(huì)方便一些,但也給我們帶來了一些困難,這里我重點(diǎn)講一個(gè)好多新手會(huì)遇到的問題,

那就是,我建立了一個(gè)基于服務(wù)的數(shù)據(jù)庫 database1.mdf?

string connstr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using(SqlConnection conn=new SqlConnection(connstr))
{
conn.Open();
using(SqlCommand cmd=conn.CreateCommand())
{
cmd.CommandText = "delete from T_Mobile";
cmd.ExecuteNonQuery();

string[] files = Directory.GetFiles(path, "*txt", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
//string title=Path.GetFileNameWithoutExtension();
using(FileStream fileStream=File.OpenRead(file))
{
using(StreamReader streamReader=new StreamReader(fileStream,System.Text.Encoding.Default))
{
string line = null;
while ((line=streamReader.ReadLine())!=null)
{
string[] strs = line.Split(',');
int startNo = Convert.ToInt32(strs[1]);
int code = Convert.ToInt32(strs[2]);
string city = strs[3];
string cardType = strs[4];
cmd.Parameters.Clear();
cmd.CommandText = "insert into T_Mobile(startNo,code,city,cardType) values(@startNo,@code,@city,@cardType)";
cmd.Parameters.Add(new SqlParameter("@startNo", startNo));
cmd.Parameters.Add(new SqlParameter("@code", code));
cmd.Parameters.Add(new SqlParameter("@city", city));
cmd.Parameters.Add(new SqlParameter("@cardType", cardType));
cmd.ExecuteNonQuery();
}
}
}
}
}
}

從選取的文件夾中讀出了所有她的.txt文件,并把它存入數(shù)據(jù)庫(事實(shí)上,這正是我學(xué)習(xí)ADO.NET時(shí)的一個(gè)練習(xí)—— 手機(jī)號(hào)碼歸屬地查詢)成功后我卻沒有在表中看見數(shù)據(jù),真相很簡(jiǎn)單,c#默認(rèn)存儲(chǔ)在\bin\Debug下了,所以我們只需在入口函數(shù)處添加一段代碼

//Program.cs

using System.Windows.Forms;

namespace MobileAscription
{
static class Program
{
/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </summary>
[STAThread]
static void Main()
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\") || dataDir.EndsWith(@"\bin\Release"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}


Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

切記要加載入口函數(shù)的最開始!!

C# 使用基于服務(wù)的數(shù)據(jù)庫的使用注意


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 九台市| 昔阳县| 密云县| 龙海市| 上饶市| 南宁市| 横峰县| 多伦县| 含山县| 柏乡县| 安塞县| 丹棱县| 兴化市| 永寿县| 寻乌县| 康马县| 攀枝花市| 天津市| 余江县| 遂平县| 湛江市| 喀喇沁旗| 泗洪县| 法库县| 濉溪县| 大埔县| 崇左市| 甘肃省| 丹凤县| 靖西县| 古丈县| 清新县| 桦南县| 赣榆县| 海丰县| 鄂托克旗| 富平县| 蓬莱市| 黎城县| 漾濞| 达州市|