从字符串转换为GUID [英] converting from string to GUID

查看:99
本文介绍了从字符串转换为GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个buttonclick事件,例如-

Hey everyone,

i have a buttonclick event such as--

protected void btnSave_Click(object sender, EventArgs e)
       {
           if (!string.IsNullOrEmpty(lblUID.Text))
           {
               pnlExternalForm.Visible = true;
               //Guid g = new Guid(lblUID.Text);
               if (!string.IsNullOrEmpty(lblUID.Text) && !string.IsNullOrEmpty(txtName.Text) && !string.IsNullOrEmpty(txtMailText.Text) && !string.IsNullOrEmpty(txtMailSubject.Text));
               {
                   UpdateRowsInDB(lblUID.Text, txtName.Text, txtMailText.Text, txtMailSubject.Text);
                   //LoadData();
                   //DataTable myDataTable = new DataTable();
                   //myDataTable.AcceptChanges();
                   HidePanel();
                   btnAdd.Visible = true;
                   btnDelete.Visible = true;
                   SetMessage(" Record is edited successfully!!");
                   if (!string.IsNullOrEmpty(gridMessage))
                   {
                       DisplayMessage(gridMessage);
                   }
               }
           }
        }





public int UpdateRowsInDB(string UID, string Name, string MailText, string MailSubject)
       {
           int retVal = 0;
           try
           {
               SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["conn"].ToString());
               SqlCommand cmd = new SqlCommand();
               conn.Open();
               cmd.Connection = conn;
               cmd.CommandText = "UPDATE Entry SET Email_TemplateName=@Email_TemplateName,Mail_Text=@Mail_Text,Mail_Subject=@Mail_Subject WHERE UID=@UID";
               cmd.Parameters.Add("@Email_TemplateName", SqlDbType.NChar).Value = Name;
               cmd.Parameters.Add("@Mail_Text", SqlDbType.NVarChar).Value = MailText;
               cmd.Parameters.Add("@Mail_Subject", SqlDbType.NChar).Value = MailSubject;
               cmd.Parameters.Add("@UID", SqlDbType.UniqueIdentifier).Value = UID;
               retVal = cmd.ExecuteNonQuery();
               conn.Close();
           }
           catch (Exception ex)
           {
               throw ex;
           }

           return retVal;
       }


我遇到错误,无法将UID的参数值从字符串转换为GUID.如何转换此值?...

谢谢
Amit


i am getting error failed to convert parameter value of UID from string to GUID.How to convert this value?...

Thanks
Amit

推荐答案

请参阅

这篇关于从字符串转换为GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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