can you help me to code a vb.net program.. i want to have a button that if i click it will add a table in the sql server database.. tnx :)) i really really need this code i only have 1 week to finish dis project :))

Recommended Answers

All 5 Replies

hello,
take a class from project menu.


Imports System.Data.sqlclient
Public Class connect
Public con As New SqlConnection("data source=J;initial catalog=donation;integrated security=true")
End Class

[connect is my class name,
j is my server name and
donation is my database name.]


take a button,in which you will code 'to create a table in sql.'

c.con.open() */open your connection*/
Dim cmd As New SqlCommand("create a table column_name datatype,column_name datatype", c.con)
cmd.executenonquery()
c.con.close()

how if i will call the value of a textbox and it will use as the name of my table how is that??

how if i will call the value of a textbox and it will use as the name of my table how is that??

please post your coding, i reply

U can use this code,...

Dim temp As String
        McodeCombo.Visible = False
        con = New SqlConnection("Data source=Suba;Initial Catalog=Raja;user id=sa")
        cmd = New SqlCommand("Insert into Machine (Mccode,Mcname,Mctype,Availhour,Rateprhr)values(@Mccode,@Mcname,@Mctype,@Availhour,@Rateprhr)", con)
        cmd.Parameters.Add("@Mccode", SqlDbType.Char, 4).Value = MccodeText.Text
        cmd.Parameters.Add("@Mcname", SqlDbType.Char, 25).Value = McnameText.Text
        cmd.Parameters.Add("@Mctype", SqlDbType.Char, 2).Value = MctypeText.Text
        If shift1CheckBox.Checked = True Then
            temp = "1"
        ElseIf Shift2CheckBox.Checked = True Then
            temp = "2"
        Else
            temp = "3"

        End If
        cmd.Parameters.Add("@Availhour", SqlDbType.Int, 4).Value = temp.ToString()
        cmd.Parameters.Add("@Rateprhr", SqlDbType.Float, 8).Value = Rprtext.Text
        con.Open()
        cmd.ExecuteNonQuery()
        MsgBox("One Record Inserted", MsgBoxStyle.OkCancel)
        con.Close()

can you help me to code a vb.net program.. i want to have a button that if i click it will add a table in the sql server database.. tnx :)) i really really need this code i only have 1 week to finish dis project :))

c.con.open()
dim cmd as new sqlcommand("create a table columnname datatype, columnname datatype....",c.con)
cmd.executenonquery()
msgbox("table created.")
c.con.close()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.