How to insert Records in Database using C# language?

前端 未结 6 2112
孤独总比滥情好
孤独总比滥情好 2020-12-01 17:26

I am just a begginer on C# so i need too much help. Now the problem is that i have designed a windows form in which there are many fields like first name, last name, address

6条回答
  •  旧时难觅i
    2020-12-01 17:53

    You should form the command with the contents of the textboxes:

    sql = "insert into Main (Firt Name, Last Name) values(" + textbox2.Text + "," + textbox3.Text+ ")";
    

    This, of course, provided that you manage to open the connection correctly.

    It would be helpful to know what's happening with your current code. If you are getting some error displayed in that message box, it would be great to know what it's saying.

    You should also validate the inputs before actually running the command (i.e. make sure they don't contain malicious code...).

提交回复
热议问题