我正在尝试通过我的 C# 代码连接到我的数据库(在同一台计算机上)。问题是我不断收到Login failed for user " "
错误...
这是我的代码的一部分:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hotel_Essencia
{
public partial class CheckIn : Form
{
public CheckIn()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Database= HotelManagement; server= Sherissa\SQLEXPRESS";
con.Open();
SqlCommand cmd = new SqlCommand("insert into CheckIn (@TransactionId,@GuestName,@RoomType,@RoomNo,@ReservationDate,@CheckInDate,@CheckOutDate,@NoOfDays,@NoOfAdults,@NoOfChildren),", con);
cmd.Parameters.AddWithValue("@TransactionId",textBox1.Text);
cmd.Parameters.AddWithValue("@GuestName", textBox2.Text);
cmd.Parameters.AddWithValue("@RoomType", textBox3.Text);
cmd.Parameters.AddWithValue("@RoomNo", textBox4.Text);
cmd.Parameters.AddWithValue("@ReservationDate", textBox5.Text);
cmd.Parameters.AddWithValue("@CheckInDate", textBox6.Text);
cmd.Parameters.AddWithValue("@CheckOutDate", textBox7.Text);
cmd.Parameters.AddWithValue("@NoOfDays", textBox8.Text);
cmd.Parameters.AddWithValue("@NoOfAdults", textBox9.Text);
cmd.Parameters.AddWithValue("@NoOfChildren", textBox10.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("DATA ADDED SUCCESSFULLY!!");
}
private void CheckIn_Load(object sender, EventArgs e)
{
}
}
}