摘抄(C#)烂尾楼

来源:互联网 发布:hosts翻墙原理 知乎 编辑:程序博客网 时间:2024/04/30 03:48
如何使用VS2013编写C#
方法/步骤
1打开VS2013软件,点击文件,然后新建,打开项目
2注意:模板要选择Visual C#,点击控制台应用程序,下面名称自己写(用英文),地址最好改一下,自己能找到就行
3一开始我们学习C#的时候会会遇到Windows窗体,这时就不是控制台应用程序了,而是Windows窗体应用程序
4这就是编写代码的主界面了
5编写完成后,需要调试,可以先启动调试然后开始执行,也可以直接开始执行
6或者点击绿色的三角形图标
7最后把写完的代码保存一下就行,也可以快捷键(Ctrl+s)。
END
编辑器设置及介绍
a.行号的显示,“工具-》选项-》文本编辑器-》C# -》 常规 -》”勾选 【行号】 就可以显示代码的行号了。显示了行号,配合快捷键CTRL+G,就有利于快速跟进代码。
b.主题皮肤调整 ,“工具-》选项-》环境-》颜色主题“,一种皮肤一种心情,随个人喜好调整。
c.字体调整。“工具-》选项-》环境-》字体和颜色“ 。好的字体,可以区分数字0和字母o,数字1和字母l及其他容易视觉混淆的字。这里推荐编程用consolas字体,其他好的字体等待你自己去发掘吧。
d.背景颜色调整。“工具-》选项-》环境-》字体和颜色-》项背景“ 。开发人员眼睛每天面对电脑超过8小时以上,好的背景色会对保护视力有好处。你可以根据自己喜欢,设置成任何颜色,这里已视力保护色(色调85,饱和度123,亮度205)为例子截图。

新手需对【工具-选项】的设置项多摸索,多尝试,才能对工具得心应手。


添加窗体

工具箱拖按钮

属性改名字大写等等

未完待续。。。

///////////////////////////////////////////////////////////////

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local);Initial Catalog=news;User ID=sa;Password=123";

SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;

for (int i=0;i<=GridView1.Rows.Count-1;i++)
{
CheckBox cbox=(CheckBox)GridView1.Rows [i].FindControl ("CheckBox1");
if (cbox.Checked == true)
{
cmd.CommandText = "update 主题表 set 审核='已审核' where 主帖编号="+GridView1 .DataKeys[i].Value;
conn.Open();
cmd.ExecuteReader();
conn.Close();
}
}
1、建立一个数据库连接对象 conn
2、指定欲连接的数据库参数:服务器为本地服务器,数据库名'news’,用户ID为'sa',密码为'123'
3、建立一个Command对象 cmd
4、将cmd的Connection变量赋值为第1步建立的对象conn
5、for循环遍历GridView1控件里的每一行
6、获得GridView1第i行里的‘CheckBox1’属性
7、判断CheckBox是否选中
8、为cmd指定执行内容,更新数据库‘主题表’里‘主帖编号’="+GridView1 .DataKeys[i].Value的那一行里‘审核’字段内容为‘已审核’
9、连接数据库
10、执行第8步指定的内容
11、关闭数据库连接

https://zhidao.baidu.com/question/236476467.html

////////////////////////////////////////////////////////////////////////////////

.\   表示项目文件所在目录之下的目录。
..\ 表示项目文件所在目录向上一级目录下的目录。
..\..\表示项目文件所在目录向上二级目录之下的目录。
 
都是针对项目文件所在目录而言,用于定位其它文件的路径位置。

 \是相对于工程目录 .\就是项目所在目录

排出一切可能,那么 . 就应该是......好吧,这里的 . 和上面无关,SQL数据库中,对于本地的表述方法有:

a、Data Source=(local)
b、Data Source="127.0.0.1"
c、Data Source=.
d、Data Source=服务器名称

e、Data Source=服务器ip

https://zhidao.baidu.com/question/528970146.html

//////////////////////////////////////////////////////////////////

Data Source- 或 -Server- 或 -Address- 或 -Addr- 或 -Network Address

      要连接的 SQL Server 实例的名称或网络地址。可以在服务器名称之后指定端口号:server=tcp:servername, portnumber
      指定本地实例时,始终使用 (local)。若要强制使用某个协议,请添加下列前缀之一:np:(local), tcp:(local), lpc:(local)
Initial Catalog- 或 -Database
       数据库的名称。

Integrated Security- 或 -Trusted_Connection
       当为 false 时,将在连接中指定用户 ID 和密码。当为 true 时,将使用当前的 Windows 帐户凭据进行身份验证。
       可识别的值为 true、false、yes、no 以及与 true 等效的 sspi(强烈推荐)。

SqlConnection.ConnectionString 属性https://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlconnection.connectionstring(VS.80).aspx

/////////////////////////////////////////////////////////////////

SQL数据库中,对于本地的表述方法有:
a、Data Source=(local)
b、Data Source="127.0.0.1"
c、Data Source=.
d、Data Source=服务器名称
e、Data Source=服务器ip
因此可见,当在对本地数据库进行连接的时候可以使用abcd均可,但是如果是连接的非本地数据库则只有d和e了。请注意本地数据库和非本地数据库的区别。
               ///////////
. 是 local的意思。。就是本机。。
一般不写IP 是为了 防止别人从 这个源码里能得到你SQL sa 的密码

https://zhidao.baidu.com/question/134366063.html

dataGridView1.Columns["QuestionId"].Visible  = false ;

///////////////////////////////////////////////////////////

用Fill()填充DataSet对象写作:
    Fill(ds,"MyNewTable")
//这样就看出 MyNewTable其实是自己随便取的名字
再读取的时候当然就得用:
    ds.Tables["MyNewTable"]

https://zhidao.baidu.com/question/57563121.html

提示

如果只需要执行SQL语句或SP,就没必要用到DataAdapter ,直接用SqlCommand的Execute系列方法就可以了。sqlDataadapter的作用是实现Dataset和DB之间的桥梁:比如将对DataSet的修改更新到数据库。
SqlDataAdapter的UpdateCommand的执行机制是:当调用SqlDataAdapter.Update()时,检查DataSet中的所有行,然后对每一个修改过的Row执行                           SqlDataAdapter.UpdateCommand ,也就是说如果未修改DataSet中的数据,SqlDataAdapter.UpdateCommand不会执行。

SqlDataAdapter
SqlDataAdapter是 DataSet和 SQL Server之间的桥接器。SqlDataAdapter通过对数据源使用适当的Transact-SQL语句映射 Fill(它可填充DataSet中的数据以匹配数据源中的数据)和 Update(它可更改数据源中的数据以匹配 DataSet中的数据)来提供这一桥接。当SqlDataAdapter填充 DataSet时,它为返回的数据创建必需的表和列(如果这些表和列尚不存在)。

问:什么是DataAdapter?
答:DataAdapter对象在DataSet与数据之间起桥梁作用

https://baike.baidu.com/item/SqlDataAdapter/3280660?fr=aladdin

第一种:Alt + *(按钮快捷键)
    在大家给button、label、menuStrip等控件设置Text属性时在名字后边加&键名就可以了,比如button1.text= "确定(&O)"。就会有快捷键了,这时候按Alt+O就可以执行按钮单击事件。

https://zhidao.baidu.com/question/1173905250959636779.html

Q. When I create a c# project from scratch in VS.NET, the generated code always have a [STAThread] attribute above the main routine. What does the STAThread attribute really do? Can I change it to MTAThread instead? I have searched website and books, no one seems to explain this well.

Asked by anon. Answered by the Wonk on February 17, 2003

A.

The STAThreadAttribute marks a thread to use the Single-Threaded COM Apartment if COM is needed. By default, .NET won't initialize COM at all. It's only when COM is needed, like when a COM object or COM Control is created or when drag 'n' drop is needed, that COM is initialized. When that happens, .NET calls the underlying CoInitializeEx function, which takes a flag indicating whether to join the thread to a multi-threaded or single-threaded apartment.

A multi-threaded apartment (MTA) in COM is more efficient, since any of a number of RPC threads from a pool can be used to handle a request. However, an object on the MTA thread needs to protect itself from multiple threads accessing it at the same time, so that efficiency comes at a cost.

The single-thread apartment (STA) in COM is inherently single-threaded and therefore no additional thread synchronization is needed. The STA is implemented using the thread's Windows message queue, which is how requests to objects on an STA are serialized. Because of how the STA thread is implemented, calls to objects on that thread are serialized with Windows message handling on that thread, making sure that everything, both the COM objects and the underlying windowing objects, e.g. HWNDs, are all synchronized. This is necessary for UI-oriented COM objects, like controls and drag 'n' drop, which must also be synchronized together with the UI.

When COM is needed .NET will call CoInitializeEx, picking the MTA by default because it's more efficient. However, to get the synchronization needed for controls, windows and drag 'n' drop, you need to mark a thread's entry point with the STAThreadAttribute to let .NET know to initialize the UI thread on the STA. All of the VS.NET project templates put that attribute in to make sure you don't forget:
大致意思是:由于很多COM在.NET环境下如果使用多线程的话,会导致引用的COM不能正常运行,而如果不声明程序为STAThread的话,.NET就会自动使用多线程来提高效率,这样就会导致不可预知的后果。

[STAThread]的含义www.cnblogs.com/huashanlin/archive/2007/07/07/809305.html

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

对于Windows XP以上的系统,加上它,那么按钮、文本框等控件会呈现XP风格的主题。
不加上,这些东西都是呈现Windows经典风格。比如文本框是向下凹陷的,按纽是一个矩形立体的。

能否具体举例说明Application.EnableVisualStyles()这句话的影响?bbs.csdn.net/topics/390903120

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1.作用:在应用程序范围内设置控件显示文本的默认方式(可以设为使用新的GDI+ , 还是旧的GDI)
true使用GDI+方式显示文本,
false使用GDI方式显示文本.
2.只能在单独运行窗体的程序中调用该方法;不能在插件式的程序中调用该方法.
3.只能在程序创建任何窗体前调用该方法,否则会引发InvalidOperationException异常.

SetCompatibleTextRenderingDefault的作用是什么?http://bbs.csdn.net/topics/100072762

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





原创粉丝点击