欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# ASP.NET+MySQL数据库命名了1个long字段,和C#的保留字重名,并且和MySQL数据库的关键字重名,如何用Parameters.AddWithValue方法插入新记录到数据库

程序员文章站 2022-08-20 14:38:44
一、数据库如下所示 命名了一个long字段,long是C#的保留字,并且long是MySQL数据库的关键字。WEB画面上有一个textbox4控件的值,如何将textbox4控件的值写入到数据库long字段中呢?二、将textbox4控件的值保存到变量mlongint mlong = Convert.ToInt32(TextBox4.Text);三、定义插入语句 MySqlCommand cmd = new MySqlCommand("insert into t......

一、数据库如下所示

     命名了一个long字段,long是C#的保留字,并且long是MySQL数据库的关键字。

C# ASP.NET+MySQL数据库命名了1个long字段,和C#的保留字重名,并且和MySQL数据库的关键字重名,如何用Parameters.AddWithValue方法插入新记录到数据库

WEB画面上有一个textbox4控件的值,如何将textbox4控件的值写入到数据库long字段中呢?

 

二、将textbox4控件的值保存到变量mlong

int mlong = Convert.ToInt32(TextBox4.Text);

三、定义插入语句

 MySqlCommand cmd = new MySqlCommand("insert into table1 set `long`=@mlong, ", Connection);
                       

四、执行插入

 cmd.Parameters.AddWithValue("@long", mlong);
           cmd.ExecuteNonQuery() ;

        说明:  set `long`=@mlong 中的 ` 符号是键盘~下面的符号,或者是键盘上tab键的上面~下的`符号,或者键盘数字1键左边的~下面的符号。

C# ASP.NET+MySQL数据库命名了1个long字段,和C#的保留字重名,并且和MySQL数据库的关键字重名,如何用Parameters.AddWithValue方法插入新记录到数据库

本文地址:https://blog.csdn.net/ba_wang_mao/article/details/109004526

相关标签: ASP.NET