Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > คืออยากทราบเกี่ยวกับการ แปลงค่าจาก String เป็น Int คับ



 

คืออยากทราบเกี่ยวกับการ แปลงค่าจาก String เป็น Int คับ

 



Topic : 024017



โพสกระทู้ ( 241 )
บทความ ( 0 )



สถานะออฟไลน์




คือ อยากแปลงข้อมูลจาก String เป็น Integer หรือ จาก Integer เป็น String ต้องให้คำสั่งอย่างไง คับ
เช่น ผมต้องการแปลงค่า dr.Item("GEN") เป็น Integer เพื่อไปใช้คำนวน
ช่วยแนะนำที คับ ขอบคุณคับบบ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-01-17 00:31:01 By : มือใหม่คับ View : 38940 Reply : 12
 

 

No. 1



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


cint(dr.Item("GEN")) แปลงเป็น Integer
cstr(dr.Item("GEN")) แปลงเป็น String






Date : 2009-01-17 01:34:32 By : kanthalak
 


 

No. 2



โพสกระทู้ ( 89 )
บทความ ( 0 )



สถานะออฟไลน์


Dim ii As Integer = Integer.Parse(dr.Item("GEN"))
Date : 2009-01-17 06:30:34 By : Zeve
 

 

No. 3

Guest


Code (VB.NET)
Dim i as Integer
If ( Not IsDBNull(dr.Item("GEN")) AND Trim(dr.Item("GEN")) <> "" Then
i = CInt(dr.Item("GEN"))
End If

Date : 2009-01-18 11:23:40 By : yanapat
 


 

No. 4



โพสกระทู้ ( 1 )
บทความ ( 0 )



สถานะออฟไลน์


มี C# ไหมเนี่ย โอยปวดหัว อีกครึ่งชั่วโมงส่งโปรเจค
Date : 2010-09-17 11:15:10 By : attakron_291033
 


 

No. 5



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Convert.toString
Convert.toInt32

msdn มีไม่เปิดละท่าน
Date : 2010-09-17 11:29:43 By : PlaKriM
 


 

No. 6



โพสกระทู้ ( 162 )
บทความ ( 0 )



สถานะออฟไลน์


int.Parse(string);
Date : 2010-09-17 15:47:15 By : superpheak
 


 

No. 7



โพสกระทู้ ( 297 )
บทความ ( 0 )



สถานะออฟไลน์


convert.toint32();
Date : 2010-09-17 23:06:32 By : nooknoname
 


 

No. 8



โพสกระทู้ ( 219 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

C#

Interger to String

int num=0;
string s_num = num.toString();



String to Integer

string str = "123456";
int num;
num = str.parseInt();
Date : 2010-09-20 10:12:30 By : mixarstudio
 


 

No. 9

Guest


เเล้วเเปลง b[4] เป็น Integer ทำอย่างไงหรอบอกทีคะ
Date : 2011-01-31 15:02:06 By : เฟิร์น
 


 

No. 10



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (C#)
int numVal = -1;
bool repeat = true;

while (repeat == true)
{
    Console.WriteLine("Enter a number between −2,147,483,648 and +2,147,483,647 (inclusive).");

    string input = Console.ReadLine();

    // ToInt32 can throw FormatException or OverflowException.
    try
    {
        numVal = Convert.ToInt32(input);
    }
    catch (FormatException e)
    {
        Console.WriteLine("Input string is not a sequence of digits.");
    }
    catch (OverflowException e)
    {
        Console.WriteLine("The number cannot fit in an Int32.");
    }
    finally
    {
        if (numVal < Int32.MaxValue)
        {
            Console.WriteLine("The new value is {0}", numVal + 1);
        }
        else
        {
            Console.WriteLine("numVal cannot be incremented beyond its current value");
        }
    }
    Console.WriteLine("Go again? Y/N");
    string go = Console.ReadLine();
    if (go == "Y" || go == "y")
    {
        repeat = true;
    }
    else
    {
        repeat = false;
    }
}
// Keep the console open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();    

Date : 2012-05-19 18:54:06 By : mr.win
 


 

No. 11



โพสกระทู้ ( 131 )
บทความ ( 12 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 7

ขอบคุณครับสำหรับคำตอบที่แก้ปัญหาเรื่องแปลง string -> int หรือ long ซึ่งแนะนำ code เพิ่มเติม คือ

Convert.ToInt64();


ซึ่งใช้คู่กับ long แล้ว รองรับหลักของตัวเลขได้มากกว่า int และ code เพิ่มเติม ได้คำตอบมากจากเว็บ http://www.dotnetfunda.com/forums/show/15619/value-was-either-too-large-or-too-small-for-an-int32 ครับ


ประวัติการแก้ไข
2019-08-21 14:08:09
Date : 2019-08-21 14:05:14 By : doanga2007
 


 

No. 12

Guest


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim constr As String = "Data Source=TCJ-039\SQLEXPRESS;Initial Catalog=DB_P1;Integrated Security=True"

Dim connection As New SqlConnection(constr)
connection.Open()

Dim sql As String = "select firstname, lastname from employees"
Dim command As New SqlCommand(sql, connection)

Dim reader As SqlDataReader = Command.executereader()
While reader.Read()
ListBox1.Items.Add($"{reader("Firstname")} {reader(1)}")
End While

connection.Close()


End Sub


code ผม Error ตรง
ListBox1.Items.Add($"{reader("Firstname")} {reader(1)}")

$ ครับ ผมควรทำไง ต้องประกาศตัวแปร ทำให้ text เป็น string ก่อนไหม ขอ code หน่อยครับ ASP.NET
Date : 2019-08-21 15:33:03 By : chatchwan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : คืออยากทราบเกี่ยวกับการ แปลงค่าจาก String เป็น Int คับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่