Windows应用程序c# [英] Windows Application c#

查看:89
本文介绍了Windows应用程序c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最近,我试图用c#n sql 2005开发Windows应用程序.我被困在可以将数据插入sql db的位置,但是当我关闭n打开应用程序时,数据就消失了.我会简单解释,
我已经在Visual Studio 08中使用服务器资源管理器创建了sql数据库(即SKTDB.mdf)和表.我的连接字符串类似于,

Hi ,

Lately i was trying to develop a windows application with c# n sql 2005. i got stucked at a point where i can insert data into the sql db but when i close n open my application, the data is gone. i''ll explain briefly,
i''ve created the sql database(i.e, SKTDB.mdf) and table using server explorer in visual studio 08. my connection string is like ,

sDBPath = Application.StartupPath + "\\DB\\SKTDB.mdf";
 if (System.IO.File.Exists(sDBPath))
 {
   connStr = "Data Source=.\\SQLEXPRESS;AttachDbFilename='" + sDBPath + "';User ID=sa;Password=1234";
 }



我的应用程序中有一张注册表.当我填写表单并提交时,数据将插入到SKTDB.mdf中的表中.但是当我重新启动我的应用程序时,表为空.我不知道原因.如果你们可以,请让我知道..



I have a registration form in my app. when i fill the form and submit , the data is inserted into the table in SKTDB.mdf. but when i restarts my application , the table is empty. I cant figure out the reason. if u guys can , pls let me know..

推荐答案

阿伦(Arun),

这不是使用C#进行数据库编程的过程.
我会简要地向您解释

假设您有以下信息要保存在数据库中.
1)用户全名
2)用户手机号码
3)用户位置

然后将此表创建到sql server
Hi Arun ,

This is not a process of database programming with C#.
I will explain you briefly

Suppose you have below information to be save in database.
1) Full Name of user
2) Mobile number of user
3) Location of user

Then Create this table into sql server
Create table registration
(
 regid uniqueidentifier, fullname nvarchar(255),Mobile nvarchar(50),Location nvarchar(50)
)


然后创建此过程


then create this procedure

CREATE PROCEDURE Saveregistration 
(
 @Full NVARCHAR(50),
 @Mobile NVARCHAR(50),
 @Location NVARCHAR(50)
)
AS
BEGIN
  INSERT INTO registration
  select newid(), @Full,@Mobile,@Location
END



然后使用下面的代码调用此过程



then use below code to call this procedure

 SqlConnection con ;
 con=new SqlConnection("Data Source=;initial catalog=Northwind;User Id=;Password= '");
con.open();

SqlCommand command = new SqlCommand("Saveregistration ",con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Full",SqlDbType.NVARCHAR,50,txtfullname.text));
command.Parameters.Add(new SqlParameter("@Mobile ",SqlDbType.NVARCHAR,50,txtMobile.txt));
command.Parameters.Add(new SqlParameter("@Location ",SqlDbType.NVARCHAR,50,txtLocation.txt));

  int i=command.ExecuteNonQuery();




希望这会有所帮助,如果是,则接受并投票回答,否则返回您的查询
--Rahul D.




Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.


这篇关于Windows应用程序c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆