如何插入我的表格 [英] How Do I Insert Into My Table
本文介绍了如何插入我的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SqlCommand cmd = new SqlCommand( INSERT INTO staff1(姓名........等)
我的sql server 2012查询:< br $>
创建 数据库 staff
使用员工
创建 table staff1(
id int primary key identity ,
name varchar ( 50 ),
surname varchar ( 50 ),
homead varchar ( 50 ),
location varchar ( 50 ),
位置 varchar ( 50 ),
cellnum varchar ( 50 ),
电子邮件 varchar ( 50 ),
additionalcontact varchar ( 50 ) ,
additionalcontactnumb varchar ( 50 ));
解决方案
首先查看连接字符串并确保连接到正确的SQL Server实例,并使用正确的数据库。
它是完全有可能你有创造编辑开发服务器中的表,并在生产服务器中使用它,反之亦然。
如果这一切都正确,请使用SSMS连接到您的数据库连接字符串中的信息 - 不要假设任何东西,你需要绝对在正确的位置,所以复制并粘贴所有字段。
检查数据库并确保表存在。可能是你忘了运行查询,或者在错误的数据库上运行它。
除了 soultion 1 由OriginalGriff [ ^ ] ...
不要使用这样的查询:
SqlCommand cmd = new SqlCommand( < span class =code-string> INSERT INTO staff1(name ........ ect ect ect)
这可能是原因严重问题,因为这样的命令是 SQL Injection [ ^ 脆弱。
如何:防止ASP.NET中的SQL注入 [ ^ ]
SQL注入攻击 [ ^ ]
SQL注入及其如何避免 [ ^ ]
做存储过程是否可以防止SQL注入? [ ^ ]
morning guys my problem is that i keep getting a eroor saying staff1 does not exist but infact it does , here is my c# code:
SqlCommand cmd = new SqlCommand("INSERT INTO staff1 (name ........ect ect ect)
my sql server 2012 query:
create database staff
use staff
create table staff1(
id int primary key identity,
name varchar(50),
surname varchar(50),
homead varchar(50),
location varchar(50),
position varchar(50),
cellnum varchar(50),
email varchar(50),
additionalcontact varchar(50),
additionalcontactnumb varchar(50));
解决方案
Start by looking at your connection string and ensure that you are connected to the right SQL Server instance, and using the right database.
It is entirely possible that you have created the table in the development server, and using it in the production server, or vice versa.
If that's all correct, use SSMS to connect to your DB using the info in the connections string - don't assume anything, you need to be absolutely in the right place, so copy and paste all fields.
Check the DB and make sure that the table exists. It may be that you forgot to run teh query, or ran it on the wrong DB.
In addition to soultion 1 by OriginalGriff[^]...
Do not use query like this:
SqlCommand cmd = new SqlCommand("INSERT INTO staff1 (name ........ect ect ect)
It might be the reason of serious problems, because such of command is SQL Injection[^] vulnerable.
How To: Protect From SQL Injection in ASP.NET[^]
SQL Injection Attacks[^]
SQL Injection and how to avoid it[^]
Do Stored Procedures Protect Against SQL Injection?[^]
这篇关于如何插入我的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文