vb 2010 mysql插入记录操作插入空白记录但没有插入数据

时间:2017-03-20 07:17:32

标签: mysql vb.net insert

我正在尝试在vb 2010中开发一个实用程序,它会将Datagridview控件的值存储到mysql表中

步骤 1)Datagrid单元格值存储在数组中 2)使用数组值.AddWithValue()函数

现状:仅插入空白记录。数据丢失。

请参阅以下代码。

http://localhost:8080/SpringMVCDemo/mvc/hello

Rajendra Nadkar

2 个答案:

答案 0 :(得分:0)

我在C#编写了一个代码,我必须将数据从数据网格存储到SQL数据库。我使用了以下代码。我认为它会对你有帮助。

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="car">
            <div class="container">
                <div class="row">
                    <div class="car-button-container">
                        <div class="col-xs-6 col-sm-3 col-md-2 col-md-offset-2 ">
                            <div class="click car-model" data-index="1">
                                Car Model 1
                            </div>
                        </div>
                        <div class="col-xs-6 col-sm-3 col-md-2">
                            <div class="click car-model" data-index="2">
                                Car Model 2
                            </div>
                        </div>
                        <div class="col-xs-6 col-sm-3 col-md-2">
                            <div class="click car-model" data-index="3">
                                Car Model 3
                            </div>
                        </div>
                        <div class="col-xs-6 col-sm-3 col-md-2">
                            <div class="click car-model" data-index="4">
                                Car Model 4
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-7 col-lg-offset-2">
                        <div class="car-image current" data-car-index="1">
                            <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727111161.png" alt="" />
                            <div class="wheelInCar left"></div>
                            <div class="wheelInCar right"></div>
                        </div>
                        <div class="car-image" data-car-index="2">
                            <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727122822.png" alt="" />
                            <div class="wheelInCar left"></div>
                            <div class="wheelInCar right"></div>
                        </div>
                        <div class="car-image" data-car-index="3">
                            <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727131353.png" alt="" />
                            <div class="wheelInCar left"></div>
                            <div class="wheelInCar right"></div>
                        </div>
                        <div class="car-image" data-car-index="4">
                            <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727151114.png" alt="" />
                            <div class="wheelInCar left"></div>
                            <div class="wheelInCar right"></div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="wheelEleContainer">
                        <div class="col-lg-1 col-lg-offset-2">
                            <div class="slectWheel">
                                <img src="http://store6.up-00.com/2017-03/148992740561243.png" alt="" />
                            </div>
                        </div>
                        <div class="col-lg-1">
                            <div class="slectWheel">
                                <img src="http://store6.up-00.com/2017-03/14899275127831.png" alt="" />
                            </div>
                        </div>
                        <div class="col-lg-1">
                            <div class="slectWheel">
                                <img src="http://store6.up-00.com/2017-03/148992740580684.png" alt="" />
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>

答案 1 :(得分:0)

好笑,我把字段名前缀@更改为?事情变得顺利了。在2月11日早些时候的一个问题中,Stelian Matei提出了这个编辑,尽管稍后Giezel Esteves推翻了它。 (2月10日用户1176607提出原始问题)

我想我需要更彻底地参考文档。无论如何,如果您或任何对此感兴趣的人,我会在这里提供工作代码。

        Dim qry As String = "INSERT INTO dyn_dwg_register (`file_name` , `file_location`, `dwg_description`, `project_id`, `created_by`)" & _
                                  " values (?file_name, ?file_location, ?dwg_description, ?project_id, ?created_by)"
        Dim sqlCommand As MySqlCommand
        sqlCommand = New MySqlCommand(qry, SQLConn)
        sqlCommand.CommandType = CommandType.Text
        With sqlCommand
            .Parameters.AddWithValue("?file_name", Arr(0))
            .Parameters.AddWithValue("?file_location", Arr(1))
            .Parameters.AddWithValue("?dwg_description", Arr(2))
            .Parameters.AddWithValue("?project_id", ProjName)
            .Parameters.AddWithValue("?created_by", Arr(2))
        End With