如何使用文本框创建数据表的名称 [英] How to create name of data table using textbox

查看:58
本文介绍了如何使用文本框创建数据表的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能用这个sql命令帮我吗



我尝试了什么:



 CON.Open(); 
SqlCommand comand = new SqlCommand(CREATE TABLE Dobavljaci + textBox2.Text(ID int,Naziv Char(50),Sjediste Char(50),Adresa Char(50),Ziroracun Char(50),sifra Char(50 ),JIB Char(50);,CON);

comand.ExecuteNonQuery();
CON.Close();



以及后来的一个如何使用

   SELECT  INSERT 





但是如何使用textbox2.text添加额外名称

所以我想创建名为Dobavljaci and textbox.text的表格







好​​吧我现在有不同的问题

 SqlCommand comand = new SqlCommand(CREATE TABLE Dobavljaci+ textBox.Text +(ID int NOT NULL identity(1,1)主键,Naziv varchar(50),Sjediste varchar(50),Adresa varchar(50),Ziroracun varchar(50),sifra varchar(50) ,JIB varchar(50),Ulaz money,Izlaz money);,CON); 我有问题,当我在textBox中输入两个单词时,他在第二个单词附近给出了错误的错误语法,当我只有一个单词时,他正在创建表格

解决方案

在关键字TABLE之后需要一个空格,目前你有TABLE< whateverisintextbox2>连接在一起。


Quote:

如何使用文本框创建数据表的名称



整个想法对我来说都是错误的,它看起来像是另一个问题的错误解决方案。

你能描述导致这个解决方案的原始问题吗?

每次他想要访问时,您是否让用户在 textbox2.text 中键入表名?



不是你问题的解决方案,而是你遇到的另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]


Can you help me with this sql command

What I have tried:

CON.Open();
     SqlCommand comand =new SqlCommand("CREATE TABLE Dobavljaci +textBox2.Text(ID int,Naziv Char(50),Sjediste Char(50),Adresa Char (50),Ziroracun Char (50),sifra Char(50),JIB Char(50);",CON);

     comand.ExecuteNonQuery();
CON.Close();


and later one how to use

"SELECT","INSERT"



But how to add additional name with textbox2.text
so i want to create table with name" Dobavljaci and textbox.text"



Ok i have different problem now

SqlCommand comand = new SqlCommand("CREATE TABLE Dobavljaci" +textBox.Text+ "(ID int NOT NULL identity(1,1) primary key,Naziv varchar(50),Sjediste varchar(50),Adresa varchar (50),Ziroracun varchar (50),sifra varchar(50),JIB varchar(50),Ulaz money,Izlaz money);", CON);


on this kind of sql command i have problem when i enter two word in textBox he is giving me error incorrect syntax near the second word when i have only one word he is creating the tables

解决方案

You need a space after the keyword TABLE, currently you have TABLE<whateverisintextbox2> concatenated together.


Quote:

How to create name of data table using textbox


The whole idea look wrong to me, it looks like a wrong solution to another problem.
Can you describe the original problem leading to this solution ?
Will you have the user to type the table name in textbox2.text every time he will want to access it ?

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]


这篇关于如何使用文本框创建数据表的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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