小编Jef*_*eff的帖子

如果值存在则更新,否则在数据库中插入值

我有一个问题,如果我的4中的值textbox- 房间类型,房间类型,费率,额外费用; 如果数据库中存在"房间类型",则更新,如果不存在,则插入到数据库.

public void existRoomType()
{
    con.Open();
    string typetable = "tblRoomType";
    string existquery = "SELECT*FROM tblRoomType WHERE RoomType = '" + txtRoomType.Text + "'";
    da = new SqlDataAdapter(existquery, con);
    da.Fill(ds, typetable);
    int counter = 0;
    if (counter < ds.Tables[typetable].Rows.Count)
    {
        cmd.Connection = con;
        string edittypequery = "UPDATE tblRoomType SET RoomType = '" + txtRoomType.Text + "', RoomRate = '" + txtRateOfRoom.Text + "', ExtraCharge = '" + txtExtraCharge.Text + "', CancelFee = '" + txtCancelFee.Text + "', …
Run Code Online (Sandbox Code Playgroud)

c# sql-server if-statement sql-update sql-insert

1
推荐指数
1
解决办法
1024
查看次数

标签 统计

c# ×1

if-statement ×1

sql-insert ×1

sql-server ×1

sql-update ×1