Data is not inserting into table?

前端 未结 5 1104
轮回少年
轮回少年 2020-12-11 11:02

My table name is Customer. It has four columns

CustomerId
CustomerName
CustomerAddress
PhoneNo

This is my c# code. I am not ge

5条回答
  •  感动是毒
    2020-12-11 11:47

    As I've said before on this site - the whole User Instance and AttachDbFileName= approach is flawed - at best! Visual Studio will be copying around the .mdf file and most likely, your INSERT works just fine - but you're just looking at the wrong .mdf file in the end!

    If you want to stick with this approach, then try putting a breakpoint on the myConnection.Close() call - and then inspect the .mdf file with SQL Server Mgmt Studio Express - I'm almost certain your data is there.

    The real solution in my opinion would be to

    1. install SQL Server Express (and you've already done that anyway)

    2. install SQL Server Management Studio Express

    3. create your database in SSMS Express, give it a logical name (e.g. VictoryDatabase)

    4. connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:

      Data Source=.\\SQLEXPRESS;Database=VictoryDatabase;Integrated Security=True
      

      and everything else is exactly the same as before...

提交回复
热议问题