[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

textbox & sqlcmd

Posted on 2008-06-20
8
Medium Priority
?
534 Views
Last Modified: 2013-12-25
i want to use textbox control entries in my sqlcd commands in vb.net.

Dim AddWithValue("@tablename",textbox.text)

sqlstr = "create table @tablename (...) "
sqlcmd.commandtext=sqlstr

I am getting an error saying "incorrect syntax near @tablename"

Can someone tell me how to use textbox entries in SQLCMD commands in vb.net
0
Comment
Question by:rogersam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 4

Accepted Solution

by:
abdulhameeds earned 1500 total points
ID: 21836979
Dim AddWithValue("@tablename",textbox.text)

sqlstr = "create table @tablename (...) "
sqlcmd.commandtext=sqlstr


first you shoud pass it as string variable  
vtable_name = "real_table_name"
sqlstr = "create table " &  vtable_name
sqlstr = sqlstr  & "(" .............


when u use it



this example


Public Function F_MAX(ByVal T_name As String, ByVal F_name As String) As Double
    On Error Resume Next
   
    Dim rs_max As Recordset
    Dim sql As String


    Set rs_max = New Recordset
    sql = "select max(" & F_name & ") as s  from " & T_name
    rs_max.Open sql, db, adOpenKeyset, adLockOptimistic
    If Not (IsNull(rs_max!s)) Then
        F_MAX = rs_max!s + 1
    Else
        F_MAX = 1
    End If


End Function
0
 
LVL 4

Expert Comment

by:abdulhameeds
ID: 21836983
its not    .Net   but the same idea
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21837045
table and column names CANNOT be passed as parameters, only values can.
so, you have to build the sql statement "manually":
sqlstr = "create table " & textbox.text & " (...) "
sqlcmd.commandtext=sqlstr

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:abdulhameeds
ID: 21837075
Sub CreateTable()
Dim RdoQuery As New RdoQuery
Dim MyValue As String
Dim ssql As String


' Create reusable rdoQuery.

Set RdoQuery.ActiveConnection = rdovisAcc
RdoQuery.SQL = "{ Call Gettablename (?)}"
RdoQuery.rdoParameters(0).Direction = rdParamOutput
RdoQuery.Execute

MyValue = "" & RdoQuery(0)

TempTable = "recycle.dbo.TMP_" & MyValue
ssql = "CREATE TABLE " & Trim(TempTable) & " (itcode char(15),itunit char(5),locode char(3),refno char(8),batchno char(10),manfdate smalldatetime,expdate smalldatetime,qty numeric(10,3),mslno numeric(5,0),slno numeric(5,0),modflag char(2))"
rdovisAcc.Execute ssql, rdExecDirect
RdoQuery.Close
Set RdoQuery = Nothing

 
 
End Sub
0
 
LVL 4

Expert Comment

by:abdulhameeds
ID: 21837079
Dim ssql As String
Dim rdoTab As rdoResultset
ImportTable = "IMPORT_" & txtSQL
ssql = "CREATE TABLE " & Trim(ImportTable) & " (Impbarcode char(15),barcode char(15),barcode1 char(15),barcode2 char(15),itbrnd char(5),itcode char(15),"
ssql = ssql & " itclr char(15),itsize char(10),Locode char(3),qty numeric(12,2),remarks char(50),FileName char(100),Flag char(1))"
rdovisAcc.Execute ssql, rdExecDirect
0
 

Author Comment

by:rogersam
ID: 22081637
well why table and column names cant be passed as parameters?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22083710
@rogersam:
because.
actually, I don't know a single database where this were possible, so it must not be terribly easy to implement such a feature, otherwise it would already be...



0
 

Author Comment

by:rogersam
ID: 22106626
well i did try it, i think i dont understand what you are trying to say.

I could create a table by importing the column names and datatypes as parameters from a text file, or directly from text boxes.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question