需要编码以在数据库中插入数据 [英] need coding for inserting data in the data base

查看:59
本文介绍了需要编码以在数据库中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者,我需要一个编码来在数据库中插入数据,我已经在sql数据库中创建了表,我需要在不使用web的情况下将以寄存器形式输入的数据插入到该sql数据库中。 config

I am a beginer i need a coding to for inserting data in the data base, i have created table in the sql database i need to insert the data that is typed in the register form in to that sql database without using web.config

推荐答案

您可能确实想要使用web.config - 事实上,如果您生产基于Web的解决方案,几乎可以保证您这样做,作为您的路径SQL Server实例可能在生产和开发方面有所不同,因此您需要两个不同的连接字符串,而web.config是通常保存的位置。尽管如此...

You probably do want to use web.config - in fact it is almost guaranteed you do if you are producign a web based solution, as the path to your SQL server instance is likely to be different in production and developement, so you will need two different conection strings, and web.config is where they are normally kept. Up to you though...
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }


您还没有发布任何代码,说明您已进行了多远或者您推荐或尝试过的内容到目前为止。



基本上,您需要 web.config 文件来存储连接字符串。



因此,如果您不想将其存储在 web.config 中,那么您可以在代码中添加一个常量页面本身并使用它。这是你的偏好。



但是因为你是初学者,我会把你的文章推荐给你使用asp.net在数据库中插入用户详细信息的注册表单示例 [ ^ ]探索如何连接到数据库并存储一份注册表格详细信息。



谢谢......
You have not posted any code saying, how far you have proceeded or what have you referred or tried so far.

Basically, you need the web.config file to store the connection string.

So, if you don''t want to store it in web.config, then you can add one constant in the code page itself and use that. That is your preference.

But as you are a beginner, I will refer you the article Registration form example to insert user details in database using asp.net[^] to explore how to connect to database and store one registration form details.

Thanks...


这篇关于需要编码以在数据库中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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